Closed HuwCampbell closed 4 years ago
Fixing this is pretty mechanical. I've fixed up a few by creating a macro UNWIND
, which sets a return variable and jumps to a label where we will call free.
UNWIND(!work,MEM,done)
do_stuff (&work, &res);
UNWIND(res,res,cleanup)
cleanup:
free(work);
done:
return ret;
This is also effecting calls to solvers, so singular matrices under the linear solve family are leaking memory.
Looking at the C code, a very common pattern is this:
where
CHECK
andOK
are macros which call return. There's an issue here in that if the calls toCHECK
fail, none of the memory allocated will be freed (until the program exits completely).