Re: Do memory allocations need to be freeed every time?
- From: viza <tom.viza@xxxxxxxx>
- Date: Thu, 19 Jun 2008 10:10:06 GMT
Hi
On Thu, 19 Jun 2008 02:23:05 -0700, Ravindra.B wrote:
Is freeing the allocated memory is really required every time, for a
program like this as freeing doesn’t bring in any change w.r.t memory
space (or) will it become a memleak some where down the line if it is
not freeed?
To avoid memory leaks, for each and every time you call malloc(), you
must call free() exactly once with the same pointer that was returned.
The only exceptions to this are:
1) if the call to malloc() returned NULL
2) if you are about to immediately terminate the program anyway*
* see
http://groups.google.co.uk/group/comp.lang.c/browse_thread/thread/
be39423f62c88e04/a8e1101586394d42
HTH
viza
.
- Follow-Ups:
- Re: Do memory allocations need to be freeed every time?
- From: Richard Heathfield
- Re: Do memory allocations need to be freeed every time?
- From: Richard Bos
- Re: Do memory allocations need to be freeed every time?
- References:
- Do memory allocations need to be freeed every time?
- From: Ravindra.B
- Do memory allocations need to be freeed every time?
- Prev by Date: Re: How to transfer an address value without using pointers
- Next by Date: Re: Do memory allocations need to be freeed every time?
- Previous by thread: Re: Do memory allocations need to be freeed every time?
- Next by thread: Re: Do memory allocations need to be freeed every time?
- Index(es):
Relevant Pages
|