Commit cea3faf1 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Extend memory re-use.

parent d23bba22
......@@ -4731,6 +4731,7 @@ gridCompareSearch(int id, void *res, void *data)
return CDI_APPLY_GO_ON;
}
/* Add grid (which must be Malloc'ed to vlist if not already found */
struct addIffNewRes cdiVlistAddGridIfNew(int vlistID, grid_t *grid, int mode)
{
/*
......
......@@ -4456,6 +4456,7 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
size_t attlen;
char attname[CDI_MAX_NAME];
double datt;
grid_t *restrict grid = NULL, *restrict proj = NULL;
for ( ncvarid = 0; ncvarid < nvars; ++ncvarid )
{
......@@ -4540,10 +4541,10 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
if ( ncvars[ncvarid].gridtype == UNDEFID || ncvars[ncvarid].gridtype == GRID_GENERIC )
if ( xdimid != UNDEFID && xdimid == ydimid && nydims == 0 ) ncvars[ncvarid].gridtype = GRID_UNSTRUCTURED;
grid_t *restrict grid = (grid_t *)Malloc(sizeof (*grid));
grid = (grid_t *)Realloc(grid, sizeof (*grid));
grid_init(grid);
cdiGridTypeInit(grid, ncvars[ncvarid].gridtype, 0);
grid_t *restrict proj = (grid_t *)Malloc(sizeof (*proj));
proj = (grid_t *)Realloc(proj, sizeof (*proj));
grid_init(proj);
cdiGridTypeInit(grid, GRID_PROJECTION, 0);
......@@ -5142,18 +5143,14 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
}
}
if (!gridAdded.isNew)
{
grid_free(grid);
Free(grid);
}
if (!projAdded.isNew)
{
grid_free(proj);
Free(proj);
}
if (gridAdded.isNew)
grid = NULL;
if (projAdded.isNew)
proj = NULL;
}
}
Free(grid);
Free(proj);
}
/* define all input zaxes */
......
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