#10 Memory leak on error in unrrdu_ccsettleMain function

Bug
open
nobody
Bug (7)
5
2012-11-26
2012-11-26
Malloc
No

FILE: teem-1.10.0-src/src/unrrdu/ccsettle.c
FUNTION: unrrdu_ccsettleMain
LINE: 57

There can be an error returned from nrrdCCSettle function (line 57) and it still could have set nval to memory created by nrrdNew().
Then the nval memory pointer is lost on the return (line 61).

Looks like if you add a nrrdNuke inside the if statement, like below, the memory leak will be fixed.

if (nrrdCCSettle(nout, airStrlen(valS) ? &nval : NULL, nin)) {
if(nval) nrrdNuke(nval); // Delete the memory if allocated.
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
fprintf(stderr, "%s: error settling connected components:\n%s", me, err);
airMopError(mop);
return 1;
}

Discussion


Log in to post a comment.