Re: Questions about malloc()
From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 11/25/04
- Next message: Dan Pop: "Re: snprint rationale?"
- Previous message: Merrill & Michele: "Re: problem to insert data"
- In reply to: Chris Torek: "Re: Questions about malloc()"
- Next in thread: Richard Bos: "Re: Questions about malloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Dan Pop: "Re: snprint rationale?"
- Previous message: Merrill & Michele: "Re: problem to insert data"
- In reply to: Chris Torek: "Re: Questions about malloc()"
- Next in thread: Richard Bos: "Re: Questions about malloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]