From: Tobias Burnus Date: Fri, 11 May 2012 23:09:30 +0000 (+0200) Subject: re PR fortran/53310 (EOSHIFT leaks memory) X-Git-Tag: releases/gcc-4.5.4~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=468b0a0db09705ca8e521fbcc9eeae35951dd3b8;p=thirdparty%2Fgcc.git re PR fortran/53310 (EOSHIFT leaks memory) 2012-05-12 Tobias Burnus PR fortran/53310 * intrinsics/eoshift2.c (eoshift2): Do not leak memory by allocating it in the loop. From-SVN: r187419 --- diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 4db2645500c9..8b2e8e777f09 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2012-05-12 Tobias Burnus + + PR fortran/53310 + * intrinsics/eoshift2.c (eoshift2): Do not leak + memory by allocating it in the loop. + 2011-08-30 Thomas Koenig Backport from trunk diff --git a/libgfortran/intrinsics/eoshift2.c b/libgfortran/intrinsics/eoshift2.c index 2fbf62e118c7..fe38d058b029 100644 --- a/libgfortran/intrinsics/eoshift2.c +++ b/libgfortran/intrinsics/eoshift2.c @@ -77,6 +77,12 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array, ret->offset = 0; ret->dtype = array->dtype; + + if (arraysize > 0) + ret->data = internal_malloc_size (size * arraysize); + else + ret->data = internal_malloc_size (1); + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) { index_type ub, str; @@ -90,12 +96,6 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array, * GFC_DESCRIPTOR_STRIDE(ret,i-1); GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); - - if (arraysize > 0) - ret->data = internal_malloc_size (size * arraysize); - else - ret->data = internal_malloc_size (1); - } } else if (unlikely (compile_options.bounds_check))