[mapserver-dev] Ticket 3559 - malloc/calloc/realloc return values should always be checked

Daniel Morissette dmorissette at mapgears.com
Tue Nov 23 13:49:49 EST 2010


Stephen Woodbridge wrote:
> 
> Forget about "small" being the criteria, and look at whether or not the
> code can recover and clean up from a failed allocation attempt. If you
> can not clean up ie: free up intermediate allocations on error returns
> then you will have memory leaks on any error and I'm not sure which is
> worse the leaks or  the exit because leaks are just a slow death that
> might impact other processes as the current consumes leaked memory and
> an exit just causes problems for the offending application.
> 

I agree with you: I'm not sure which one is better between slow leaks
from improper cleanup on errors, or a brute force exit. I would add that
another factor to consider is to try to avoid unnecessarily increasing
code complexity with conditional code to try to recover from out of
memory situations where there is not much we can do anyway.

So I'd second what Steve suggests and do a proper cleanup when possible,
otherwise just go with msSmallAlloc/exit if the code cannot easily do a
proper cleanup, even in cases where the allocation may not clearly meet
the "small" criteria.

Daniel
-- 
Daniel Morissette
http://www.mapgears.com/


More information about the mapserver-dev mailing list