Claudio Jeker <cje...@diehard.n-r-g.com> writes:

> On Tue, May 06, 2014 at 03:32:06PM +0200, Jérémie Courrèges-Anglas wrote:
>> Denis Fondras <open...@ledeuns.net> writes:
>> 
>> >> By the OS, which cleans up after the process exits.  If it wasn't that
>> >> way, we'd all have a much shorter uptime...
>> >> 
>> >
>> > Thank you Jérémie :)
>> > I had not considered it as I can see
>> >
>> > ...
>> > free(ibuf_rde);
>> > ...
>> > free(ibuf_main);
>> > ...
>> >
>> > at the end of session_main() in session.c.
>> 
>> Maybe you should consider this as "best effort".  It's a good thing to
>> clean up at the end of a function in an executable, even in error cases
>> where the end result is exit(1) / err() / fatal(), because code gets
>> copied and used in different contexts (where cleaning up could be
>> necessary).
>
> Bad advice, you should not cleanup before err() or fatal() ever.
> It could very well be that you hit a bug that trashed your heap and
> calling free() will not solve anything. Doing cleanup before exit is only
> used to check for memleaks with simple tools.

I do agree with your argument, but I find it hard to apply every time.
When looking at one function it can be hard to see if the caller(s)
will call fatal() or not (not all errors are fatal, after all).

Sorry for the bad advice.

[...]

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to