Re: free()
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 10 Feb 2007 04:13:13 -0800
dbansal wrote:
Hi group,
I have a question to ask you all. I have allocated some chunk of
memory using ptr=(int*)malloc().
The cast is not needed, indeed even counterproductive, in C.
now I am trying to free that memory
using free((void*)ptr).
Same as above.
My question is does free() make ptr NULL?
No.
If not how do we know whether ptr memory has been freed already and we
should not try to free the same memory twice. Man pages does not tell
anything about this behavoiur.
As long as you pass a value previously obtained from malloc() calloc()
or realloc(), free() will succeed. If the argument is a null pointer
value, free() does nothing.
There's no mechanism in C to tell you if a pointer value points to
validly addressable memory or not. You'll have to keep track of such
things yourself. One safe practise is to immediately set a pointer to
NULL after calling free() on it. Passing a null pointer to free() is
harmless.
.
- Follow-Ups:
- Re: free()
- From: Racaille
- Re: free()
- From: Keith Thompson
- Re: free()
- References:
- free()
- From: dbansal
- free()
- Prev by Date: Re: anti-aliasing
- Next by Date: Re: anti-aliasing
- Previous by thread: Re: free()
- Next by thread: Re: free()
- Index(es):
Relevant Pages
|