aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoodale <goodale@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2000-12-14 23:10:08 +0000
committergoodale <goodale@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2000-12-14 23:10:08 +0000
commit132fe634f31b732bd69f8935582a3699731d89ae (patch)
treed2f17ef34841d379ca6a1db72182be02f550452d
parentc5622c14a29188f03e2cd47facf5247b9b24ece3 (diff)
A bit of memory checking; still needs more.
Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@35 94b1c47f-dcfd-45ef-a468-0854c0e9e350
-rw-r--r--src/Startup.c133
1 files changed, 70 insertions, 63 deletions
diff --git a/src/Startup.c b/src/Startup.c
index 4fa5eab..fb98e2f 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -134,84 +134,91 @@ static void *IOASCII_SetupGH (tFleshConfig *config,
/* allocate the GH extension and its components */
newGH = (asciiioGH *) malloc (sizeof (asciiioGH));
- i = CCTK_NumVars ();
- newGH->do_out1D = (char *) malloc (i * sizeof (char));
- newGH->do_out2D = (char *) malloc (i * sizeof (char));
- newGH->out1D_last = (int *) malloc (i * sizeof (int));
- newGH->out2D_last = (int *) malloc (i * sizeof (int));
- newGH->spxyz = (int ***) malloc (CCTK_MaxDim() * sizeof (int **));
- newGH->sp2xyz = (int **) malloc (3 * sizeof (int *));
-
- for (i = CCTK_MaxDim () - 1; i >= 0; i--)
+ if(newGH)
{
- newGH->spxyz[i] = (int **) malloc (3 * sizeof (int *));
- newGH->spxyz[i][0] = (int *) malloc (3 * sizeof (int ));
- newGH->spxyz[i][1] = (int *) malloc (3 * sizeof (int ));
- newGH->spxyz[i][2] = (int *) malloc (3 * sizeof (int ));
-
- newGH->sp2xyz[i] = (int *) malloc (3 * sizeof (int ));
- }
-
- /* How often to output */
- newGH->out1D_every = out_every > 0 ? out_every : -1;
- if (out1D_every > 0)
- {
- newGH->out1D_every = out1D_every;
- }
- newGH->out2D_every = out_every > 0 ? out_every : -1;
- if (out2D_every > 0)
- {
- newGH->out2D_every = out2D_every;
- }
+ i = CCTK_NumVars ();
+ newGH->do_out1D = (char *) malloc (i * sizeof (char));
+ newGH->do_out2D = (char *) malloc (i * sizeof (char));
+ newGH->out1D_last = (int *) malloc (i * sizeof (int));
+ newGH->out2D_last = (int *) malloc (i * sizeof (int));
+ newGH->spxyz = (int ***) malloc (CCTK_MaxDim() * sizeof (int **));
+ newGH->sp2xyz = (int **) malloc (3 * sizeof (int *));
+
+ for (i = CCTK_MaxDim () - 1; i >= 0; i--)
+ {
+ newGH->spxyz[i] = (int **) malloc (3 * sizeof (int *));
+ newGH->spxyz[i][0] = (int *) malloc (3 * sizeof (int ));
+ newGH->spxyz[i][1] = (int *) malloc (3 * sizeof (int ));
+ newGH->spxyz[i][2] = (int *) malloc (3 * sizeof (int ));
- /* Deal with the output directories */
- /* Check whether "outdirXD" was set.
- If so take this dir otherwise default to "IO::outdir" */
- newGH->outdir1D = CCTK_ParameterQueryTimesSet("outdir1D",CCTK_THORNSTRING)>0 ?
- strdup (outdir1D) : strdup (outdir);
- newGH->outdir2D = CCTK_ParameterQueryTimesSet("outdir2D",CCTK_THORNSTRING)>0 ?
- strdup (outdir2D) : strdup (outdir);
+ newGH->sp2xyz[i] = (int *) malloc (3 * sizeof (int ));
+ }
- /* create the output dir */
- if (CCTK_MyProc (GH) == 0)
- {
- i = CCTK_CreateDirectory (0755, newGH->outdir1D);
- if (i < 0)
+ /* How often to output */
+ newGH->out1D_every = out_every > 0 ? out_every : -1;
+ if (out1D_every > 0)
{
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_InitGH: Problem creating 1D output directory '%s'",
- newGH->outdir1D);
+ newGH->out1D_every = out1D_every;
}
- if (i > 0)
+ newGH->out2D_every = out_every > 0 ? out_every : -1;
+ if (out2D_every > 0)
{
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_InitGH: 1D output directory '%s' already exists",
- newGH->outdir1D);
+ newGH->out2D_every = out2D_every;
}
- i = CCTK_CreateDirectory (0755, newGH->outdir2D);
- if (i < 0)
+
+ /* Deal with the output directories */
+ /* Check whether "outdirXD" was set.
+ If so take this dir otherwise default to "IO::outdir" */
+ newGH->outdir1D = CCTK_ParameterQueryTimesSet("outdir1D",CCTK_THORNSTRING)>0 ?
+ strdup (outdir1D) : strdup (outdir);
+ newGH->outdir2D = CCTK_ParameterQueryTimesSet("outdir2D",CCTK_THORNSTRING)>0 ?
+ strdup (outdir2D) : strdup (outdir);
+
+ /* create the output dir */
+ if (CCTK_MyProc (GH) == 0)
{
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_InitGH: Problem creating 2D output directory '%s'",
- newGH->outdir2D);
+ i = CCTK_CreateDirectory (0755, newGH->outdir1D);
+ if (i < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_InitGH: Problem creating 1D output directory '%s'",
+ newGH->outdir1D);
+ }
+ if (i > 0)
+ {
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_InitGH: 1D output directory '%s' already exists",
+ newGH->outdir1D);
+ }
+ i = CCTK_CreateDirectory (0755, newGH->outdir2D);
+ if (i < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_InitGH: Problem creating 2D output directory '%s'",
+ newGH->outdir2D);
+ }
+ if (i > 0)
+ {
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_InitGH: 2D output directory '%s' already exists",
+ newGH->outdir2D);
+ }
}
- if (i > 0)
+
+ for (i = 0; i < CCTK_NumVars (); i++)
{
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_InitGH: 2D output directory '%s' already exists",
- newGH->outdir2D);
+ newGH->out1D_last[i] = -1;
+ newGH->out2D_last[i] = -1;
}
- }
- for (i = 0; i < CCTK_NumVars (); i++)
+ newGH->filenameList1D = NULL;
+ newGH->fileList_2D = NULL;
+ }
+ else
{
- newGH->out1D_last[i] = -1;
- newGH->out2D_last[i] = -1;
+ CCTK_WARN(0, "Unable to allocate memory for GH in IOASCII");
}
- newGH->filenameList1D = NULL;
- newGH->fileList_2D = NULL;
-
return (newGH);
}