Re: free()
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Tue, 13 Feb 2007 21:38:58 +0000
Christopher Benson-Manica said:
Ian Collins <ian-news@xxxxxxxxxxx> wrote:
Richard Bos wrote:
The problem with that is "attempting". You will, sooner or later,
fail in your attempt. And then, because you believe that all your
pointers are either null or valid, you will not be able to find the
bug until
Can you cite an example where setting a pointer to NULL could mask a
bug? The way I see it is there are three things you can do with a
pointer, test it, dereference it and free it. Once set to NULL, the
first to will fail and the third is harmless.
You missed Richard's point. The problem lies not in setting the
pointer to NULL, but in *believing* one has when in fact one has not.
Lots of problems can arise from believing one has done something when in
fact one has not. That doesn't mean that the something is a bad thing
to do.
Short of writing an entire pointer management subsystem, there isn't
much you can do with a pointer to check it for validity, but you *can*
test it against NULL. If you know it's NULL, you know it's invalid. If
it isn't NULL, you can't be sure either way. So setting it to NULL when
it would otherwise be indeterminate is a Good Thing, because it
increases the amount of information available to you at a trivial cost.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: free()
- From: Beej
- Re: free()
- References:
- free()
- From: dbansal
- Re: free()
- From: santosh
- Re: free()
- From: Racaille
- Re: free()
- From: santosh
- Re: free()
- From: Richard Bos
- Re: free()
- From: Ian Collins
- Re: free()
- From: Christopher Benson-Manica
- free()
- Prev by Date: Re: Accessing web with a C program
- Next by Date: Self copying code
- Previous by thread: Re: free()
- Next by thread: Re: free()
- Index(es):
Relevant Pages
|