[Bug fortran/53310] [4.5/4.6/4.7/4.8 Regression] EOSHIFT leaks memory
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu May 10 21:47:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53310
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org
Target Milestone|--- |4.6.4
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-10 21:27:52 UTC ---
Draft patch. I think it makes sense to move the allocation out of the loop:
--- a/libgfortran/intrinsics/eoshift2.c
+++ b/libgfortran/intrinsics/eoshift2.c
@@ -79,2 +79,6 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array,
ret->dtype = array->dtype;
+
+ /* xmalloc allocates a single byte for zero size. */
+ ret->base_addr = xmalloc (size * arraysize);
+
for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
@@ -92,6 +96,2 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array,
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
-
- /* xmalloc allocates a single byte for zero size. */
- ret->base_addr = xmalloc (size * arraysize);
-
}
More information about the Gcc-bugs
mailing list