Re: Questions about malloc()

From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 11/25/04


Date: 25 Nov 2004 16:25:31 GMT

In <co32jv01uq6@news4.newsguy.com> Chris Torek <nospam@torek.net> writes:

>For this sort of reason, I do not mind:
>
> free(ptr), ptr = NULL;
>
>but in many cases it does not really add much to debuggability.
>It *does* help if (but only if) you can establish an invariant:
>"ptr is either NULL, or a valid pointer" -- and that depends greatly
>on the context in which "ptr" appears.

To expand a bit on your point: the above construct, which can be trivially
automated with a macro wrapper for free() is useless when you have other
pointers pointing in the block being deallocated. If you don't nullify
*all* of them right after (or before) calling free(), nullifying only one
of them is not going to buy you much.

Dan

-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
           Currently looking for a job in the European Union