From 468b0a0db09705ca8e521fbcc9eeae35951dd3b8 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Sat, 12 May 2012 01:09:30 +0200 Subject: [PATCH] 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 --- libgfortran/ChangeLog | 6 ++++++ libgfortran/intrinsics/eoshift2.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) 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)) -- 2.47.2