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

Prevent memory leak.

* Also add code to test for it with valgrind.
parent 3721c2bf
......@@ -285,6 +285,7 @@ void vlistCopy(int vlistID2, int vlistID1)
vlist_check_ptr(__func__, vlistptr1);
vlist_check_ptr(__func__, vlistptr2);
var_t *vlist2vars = vlistptr2->vars;
vlist_copy(vlistptr2, vlistptr1);
vlistCopyVarAtts(vlistID1, CDI_GLOBAL, vlistID2, CDI_GLOBAL);
......@@ -294,7 +295,7 @@ void vlistCopy(int vlistID2, int vlistID1)
int nvars = vlistptr1->nvars;
//vlistptr2->varsAllocated = nvars;
vlistptr2->vars = (var_t *) malloc(vlistptr2->varsAllocated*sizeof(var_t));
vlistptr2->vars = xrealloc(vlist2vars, vlistptr2->varsAllocated*sizeof(var_t));
memcpy(vlistptr2->vars, vlistptr1->vars, vlistptr2->varsAllocated*sizeof(var_t));
for ( int varID = 0; varID < nvars; varID++ )
......
......@@ -157,6 +157,9 @@ int defineVlist ( int gridID, int zaxisID, int taxisID )
vlistDefVarName(vlistID, varID2, "varname2");
vlistDefAttTxt(vlistID, varID2, "txt demo", 6, "banana");
vlistDefTaxis(vlistID, taxisID);
int vlistID2 = vlistCreate();
vlistDefVar(vlistID2, gridID, zaxisID, TIME_VARIABLE);
vlistCopy(vlistID2, vlistID);
return vlistID;
}
......
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