From 5568329709d582d49ed39dfb2dec8791e82adf63 Mon Sep 17 00:00:00 2001 From: yye00 Date: Wed, 7 Dec 2005 23:01:30 +0000 Subject: Added free statements for local variables, added a check condition not to allocate memory for zero dimensional (scalar) reductions. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGHReduce/trunk@80 d60812e6-3970-4df4-986e-c251b06effeb --- src/ReduceArraysGlobally.c | 32 +++++++++++++++++++++----------- src/ReduceGA.c | 27 +++++++++++++++++++-------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/ReduceArraysGlobally.c b/src/ReduceArraysGlobally.c index 23f4a91..b5418f9 100644 --- a/src/ReduceArraysGlobally.c +++ b/src/ReduceArraysGlobally.c @@ -180,7 +180,6 @@ static int ReduceArraysGlobally (const cGH *GH, CCTK_INT * min_array_subscript; CCTK_INT * array_lsh; CCTK_INT * input_array_dims; - CCTK_INT * input_array_gz; /* temporary complex variables*/ @@ -223,12 +222,15 @@ static int ReduceArraysGlobally (const cGH *GH, dim = input_dims; /* allocate memory for the array of the dimensions of the input arrays */ - lower_array_bounds = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - min_array_subscript = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - array_lsh = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - input_array_dims = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - input_array_gz = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - + if (dim>0) + { + lower_array_bounds = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + min_array_subscript = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + array_lsh = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + input_array_dims = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + input_array_gz = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + } + /* calculate index ranges */ for ( i=0; i < dim; i++) { @@ -769,12 +771,20 @@ static int ReduceArraysGlobally (const cGH *GH, break; #endif } - } - num_points = total_num_points; - weight_sum = total_weight_sum; free (local_outvals); + } + num_points = total_num_points; + weight_sum = total_weight_sum; #endif - + if (dim >0) + { + free (lower_array_bounds); + free (min_array_subscript); + free (array_lsh); + free (input_array_dims); + free (input_array_gz); + } + if (perform_division == 0) { if (weight_on == 1) diff --git a/src/ReduceGA.c b/src/ReduceGA.c index 29ddd07..6bcc08e 100644 --- a/src/ReduceGA.c +++ b/src/ReduceGA.c @@ -207,12 +207,15 @@ static int ReduceGridArrays (const cGH *GH, dim = CCTK_GroupDimFromVarI(input_array_variable_indices[0]); /* allocate memory for the array of the dimensions of the input arrays */ - lower_array_bounds = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - min_array_subscript = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - array_lsh = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - input_array_dims = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - input_array_gz = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); - + if (dim >0) + { + lower_array_bounds = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + min_array_subscript = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + array_lsh = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + input_array_dims = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + input_array_gz = (CCTK_INT *)malloc (dim *sizeof(CCTK_INT)); + } + /* find out the types of the input arrays and put that */ /* in an array ipughGH->GFExtras[dim]->lnsize[i]*/ for ( i = 0; i < N_input_arrays; i++) @@ -771,12 +774,20 @@ static int ReduceGridArrays (const cGH *GH, break; #endif } + free (local_outvals); } num_points = total_num_points; weight_sum = total_weight_sum; - free (local_outvals); #endif - + if (dim >0) + { + free (lower_array_bounds); + free (min_array_subscript); + free (array_lsh); + free (input_array_dims); + free (input_array_gz); + } + if (perform_division == 0) { if (weight_on == 1) -- cgit v1.2.3