aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorallen <allen@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2001-12-14 11:05:30 +0000
committerallen <allen@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2001-12-14 11:05:30 +0000
commitbc6291eb873b0261bbcdd43abc9d22d30d774026 (patch)
tree357f3a8da2279174e3eeb7a4703f3d1e1393ea42
parent5c46410189d2496e211208af6f43d408ca8f0eb1 (diff)
Fixed small memory leak
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@138 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-rw-r--r--src/Utils.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/src/Utils.c b/src/Utils.c
index e9f11f9..ef3ceff 100644
--- a/src/Utils.c
+++ b/src/Utils.c
@@ -83,7 +83,9 @@ int IOUtil_1DLines (const cGH *GH,
int dim, dir;
char coord_system_name[20];
CCTK_REAL *lower_range, *upper_range;
+ int retval;
+ retval = 0;
/* allocate arrays for ranges */
lower_range = (CCTK_REAL *) calloc (2 * num_dims, sizeof (CCTK_REAL));
@@ -120,60 +122,64 @@ int IOUtil_1DLines (const cGH *GH,
}
}
- return (-1);
+ retval=-1;
}
/* now set the slice center for each line
according to origin_index[] or origin_phys[] */
- for (dir = 0; dir < num_dims; dir++)
+
+ if (!retval)
{
- for (dim = 0; dim < num_dims; dim++)
+ for (dir = 0; dir < num_dims; dir++)
{
- if (dim == dir)
- {
- /* line always starts at the first point */
- slice_center[dir][dim] = 0;
- }
- else if (origin_index && origin_index[dir][dim] >= 0)
- {
-/* FIXME: check upper index bounds also ?? */
- slice_center[dir][dim] = origin_index[dir][dim];
- }
- else if (lower_range[dim] > origin_phys[dir][dim] ||
- upper_range[dim] < origin_phys[dir][dim])
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOUtil_1DLines: %c-coordinate for slice center of 1D "
- "lines in %c-direction (%f) is out of grid coordinates "
- "range (%f, %f)",
- 'x' + dim, 'x' + dir, (double) origin_phys[dir][dim],
- (double) lower_range[dim], (double) upper_range[dim]);
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOUtil_1DLines: no 1D %c-line output will be written for "
- "%dD variables with this slice center default",
- 'x' + dir, num_dims);
-
- slice_center[dir][dim] = -1;
- }
- else
+ for (dim = 0; dim < num_dims; dim++)
{
- /* Find index for first point above the chosen coordinate */
- slice_center[dir][dim] =
- ceil ((origin_phys[dir][dim] - lower_range[dim]) /
- GH->cctk_delta_space[dim] - 1e-6);
+ if (dim == dir)
+ {
+ /* line always starts at the first point */
+ slice_center[dir][dim] = 0;
+ }
+ else if (origin_index && origin_index[dir][dim] >= 0)
+ {
+ /* FIXME: check upper index bounds also ?? */
+ slice_center[dir][dim] = origin_index[dir][dim];
+ }
+ else if (lower_range[dim] > origin_phys[dir][dim] ||
+ upper_range[dim] < origin_phys[dir][dim])
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOUtil_1DLines: %c-coordinate for slice center of 1D "
+ "lines in %c-direction (%f) is out of grid coordinates "
+ "range (%f, %f)",
+ 'x' + dim, 'x' + dir, (double) origin_phys[dir][dim],
+ (double) lower_range[dim], (double) upper_range[dim]);
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOUtil_1DLines: no 1D %c-line output will be written for "
+ "%dD variables with this slice center default",
+ 'x' + dir, num_dims);
+
+ slice_center[dir][dim] = -1;
+ }
+ else
+ {
+ /* Find index for first point above the chosen coordinate */
+ slice_center[dir][dim] =
+ ceil ((origin_phys[dir][dim] - lower_range[dim]) /
+ GH->cctk_delta_space[dim] - 1e-6);
#ifdef DEBUG_IOUTIL
- printf("spxyz for %c-coord of lines in %c-direction is %d\n",
- 'x' + dim,'x' + dir, slice_center[dir][dim]);
+ printf("spxyz for %c-coord of lines in %c-direction is %d\n",
+ 'x' + dim,'x' + dir, slice_center[dir][dim]);
#endif
+ }
}
}
}
-
+
/* free allocated resources */
free (lower_range);
- return (0);
+ return retval;
}