Commit a35ab86a authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cgribexDecode: allocate cgribexp if needed.

parent 69001163
......@@ -135,6 +135,7 @@ DecodeArgs grb_read_raw_data(stream_t *streamptr, int recID, int memtype, void *
if ( recsize == 0 ) Error("Internal problem! Recordsize is zero for record %d at timestep %d", recID+1, tsID+1);
void *cgribexp = (gribbuffer && streamptr->record->cgribexp) ? streamptr->record->cgribexp : NULL;
if (!gribbuffer) gribbuffer = Malloc(streamptr->record->buffersize);
if (!data) data = Malloc(gridsize*(memtype == MEMTYPE_FLOAT ? sizeof(float) : sizeof(double)));
......@@ -157,7 +158,7 @@ DecodeArgs grb_read_raw_data(stream_t *streamptr, int recID, int memtype, void *
.outZip = &streamptr->tsteps[tsID].records[recID].zip,
.filetype = streamptr->filetype,
.memtype = memtype,
.cgribexp = streamptr->record->cgribexp,
.cgribexp = cgribexp,
.gribbuffer = gribbuffer,
.recsize = recsize,
.data = data,
......
......@@ -1297,7 +1297,8 @@ int cgribexDecode(int memtype, void *cgribex, void *gribbuffer, size_t gribsize,
{
int status = 0;
cgribexrec_t *cgribexp = (cgribexrec_t *) cgribex;
bool lalloc = cgribex == NULL;
cgribexrec_t *cgribexp = (cgribexrec_t *) (lalloc ? cgribexNew() : cgribex);
int *isec0 = cgribexp->sec0;
int *isec1 = cgribexp->sec1;
......@@ -1352,6 +1353,8 @@ int cgribexDecode(int memtype, void *cgribex, void *gribbuffer, size_t gribsize,
}
}
if (lalloc) cgribexDelete(cgribexp);
return status;
}
......
Markdown is supported
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