Commit 1f102f51 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Split.c: cleanup memory allocation

parent 2aa81e10
......@@ -124,7 +124,6 @@ void *Split(void *argument)
if ( operatorID == SPLITCODE )
{
int *codes = NULL;
nsplit = 0;
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -139,9 +138,9 @@ void *Split(void *argument)
}
}
codes = (int*) malloc(nsplit*sizeof(int));
vlistIDs = (int*) malloc(nsplit*sizeof(int));
streamIDs = (int*) malloc(nsplit*sizeof(int));
int codes[nsplit];
memcpy(codes, itmp, nsplit*sizeof(int));
for ( index = 0; index < nsplit; index++ )
......@@ -186,12 +185,10 @@ void *Split(void *argument)
streamIDs[index] = streamOpenWrite(fileargument, cdoFiletype());
file_argument_free(fileargument);
}
if ( codes ) free(codes);
}
else if ( operatorID == SPLITPARAM )
{
char paramstr[32];
int *params = NULL;
nsplit = 0;
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -206,9 +203,9 @@ void *Split(void *argument)
}
}
params = (int*) malloc(nsplit*sizeof(int));
vlistIDs = (int*) malloc(nsplit*sizeof(int));
streamIDs = (int*) malloc(nsplit*sizeof(int));
int params[nsplit];
memcpy(params, itmp, nsplit*sizeof(int));
for ( index = 0; index < nsplit; index++ )
......@@ -243,11 +240,9 @@ void *Split(void *argument)
streamIDs[index] = streamOpenWrite(fileargument, cdoFiletype());
file_argument_free(fileargument);
}
if ( params ) free(params);
}
else if ( operatorID == SPLITTABNUM )
{
int *tabnums = NULL;
nsplit = 0;
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -262,9 +257,9 @@ void *Split(void *argument)
}
}
tabnums = (int*) malloc(nsplit*sizeof(int));
vlistIDs = (int*) malloc(nsplit*sizeof(int));
streamIDs = (int*) malloc(nsplit*sizeof(int));
int tabnums[nsplit];
memcpy(tabnums, itmp, nsplit*sizeof(int));
for ( index = 0; index < nsplit; index++ )
......@@ -295,7 +290,6 @@ void *Split(void *argument)
streamIDs[index] = streamOpenWrite(fileargument, cdoFiletype());
file_argument_free(fileargument);
}
if ( tabnums ) free(tabnums);
}
else if ( operatorID == SPLITNAME )
{
......@@ -333,7 +327,7 @@ void *Split(void *argument)
}
else if ( operatorID == SPLITLEVEL )
{
double level, *levels = NULL;
double level;
nzaxis = vlistNzaxis(vlistID1);
nsplit = 0;
for ( index = 0; index < nzaxis; index++ )
......@@ -350,9 +344,9 @@ void *Split(void *argument)
}
}
levels = (double*) malloc(nsplit*sizeof(double));
vlistIDs = (int*) malloc(nsplit*sizeof(int));
streamIDs = (int*) malloc(nsplit*sizeof(int));
double levels[nsplit];
memcpy(levels, ftmp, nsplit*sizeof(double));
for ( index = 0; index < nsplit; index++ )
......@@ -383,18 +377,16 @@ void *Split(void *argument)
streamIDs[index] = streamOpenWrite(fileargument, cdoFiletype());
file_argument_free(fileargument);
}
if ( levels ) free(levels);
}
else if ( operatorID == SPLITGRID )
{
int gridID, *gridIDs = NULL;
int gridID;
nsplit = vlistNgrids(vlistID1);
gridIDs = (int*) malloc(nsplit*sizeof(int));
vlistIDs = (int*) malloc(nsplit*sizeof(int));
streamIDs = (int*) malloc(nsplit*sizeof(int));
int gridIDs[nsplit];
for ( index = 0; index < nsplit; index++ )
gridIDs[index] = vlistGrid(vlistID1, index);
......@@ -426,18 +418,16 @@ void *Split(void *argument)
streamIDs[index] = streamOpenWrite(fileargument, cdoFiletype());
file_argument_free(fileargument);
}
if ( gridIDs ) free(gridIDs);
}
else if ( operatorID == SPLITZAXIS )
{
int zaxisID, *zaxisIDs = NULL;
int zaxisID;
nsplit = vlistNzaxis(vlistID1);
zaxisIDs = (int*) malloc(nsplit*sizeof(int));
vlistIDs = (int*) malloc(nsplit*sizeof(int));
streamIDs = (int*) malloc(nsplit*sizeof(int));
int zaxisIDs[nsplit];
for ( index = 0; index < nsplit; index++ )
zaxisIDs[index] = vlistZaxis(vlistID1, index);
......@@ -468,7 +458,6 @@ void *Split(void *argument)
streamIDs[index] = streamOpenWrite(fileargument, cdoFiletype());
file_argument_free(fileargument);
}
if ( zaxisIDs ) free(zaxisIDs);
}
else
{
......
......@@ -922,7 +922,7 @@ void hetaeta(int ltq, int ngp, const int *imiss,
return;
}
/*
#if defined(TEST_HETAETA)
int main (int argc, char *argv[])
{
double a2[41] = {
......@@ -1107,4 +1107,4 @@ int main (int argc, char *argv[])
return 0;
}
*/
#endif
......@@ -38,11 +38,10 @@ int readInstitution(const char *instfile)
int nvar = 0, maxvar = 4;
char name[1024], longname[1024];
int center = UNDEFID, subcenter = UNDEFID;
FILE *instfp;
instfp = fopen(instfile, "r");
FILE *instfp = fopen(instfile, "r");
if ( instfp == NULL ) return (instID);
if ( instfp == NULL ) return instID;
while ( readline(instfp, line, 1024) )
{
......@@ -92,18 +91,14 @@ int readInstitution(const char *instfile)
if ( instID == UNDEFID )
instID = institutDef(center, subcenter, name, longname);
return (instID);
return instID;
}
void defineInstitution(char *instarg)
{
char *instname;
int instID;
instname = instarg;
instID = readInstitution(instname);
char *instname = instarg;
int instID = readInstitution(instname);
if ( instID == UNDEFID )
instID = institutInq(0, 0, instname, NULL);
......
......@@ -28,7 +28,6 @@
int defineTable(char *tablearg)
{
int tableID = CDI_UNDEFID;
char *tablename = tablearg;
if ( fileExists(tablename) ) tableID = tableRead(tablename);
......@@ -36,17 +35,14 @@ int defineTable(char *tablearg)
if ( tableID == CDI_UNDEFID )
{
char *tablepath = getenv("CD_TABLEPATH");
if ( tablepath )
{
char *tablefile = NULL;
int len = sizeof(tablepath) + sizeof(tablename) + 3;
tablefile = (char*) malloc(len);
char *tablefile[len];
strcpy(tablefile, tablepath);
strcat(tablefile, "/");
strcat(tablefile, tablename);
if ( fileExists(tablename) ) tableID = tableRead(tablefile);
free(tablefile);
}
}
......@@ -56,5 +52,5 @@ int defineTable(char *tablearg)
if ( tableID == CDI_UNDEFID )
Error("table <%s> not found", tablename);
return (tableID);
return tableID;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment