Re: Memory leak when internal pointer passed out as parameter
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 4 Apr 2007 04:20:33 -0700
Daniel Rudy wrote:
At about the time of 4/3/2007 11:52 AM, Mike stated the following:
<snip>
Rational Purify checked the code, and reported memory leak on foo1
when we allocate memory. I assum e that the compiler will allocate a
new block of memory when foo1 returns. Then the memory allocated
within foo1 will remain in the system heap forever. However I have no
way to verify it.
The allocated memory will be returned to the system heap when the
program exits, if there is a memory leak.
Nowhere does the C Standard guarantee this. Yes, modern memory
protected operating systems do reclaim a program's allocated memory
after the latter's termination, but C implementations exist on systems
that're not as sophisticated or capable. A conforming C program must
not make such assumptions.
You've also ignored the case of long-running processes like UNIX
deamons. Memory leaks in such programs can cause the system memory to
be slowly eaten up.
It's always better to explicitly free any memory when you're done with
it.
<snip>
.
- Follow-Ups:
- Re: Memory leak when internal pointer passed out as parameter
- From: Daniel Rudy
- Re: Memory leak when internal pointer passed out as parameter
- References:
- Memory leak when internal pointer passed out as parameter
- From: Mike
- Re: Memory leak when internal pointer passed out as parameter
- From: Walter Roberson
- Re: Memory leak when internal pointer passed out as parameter
- From: Mike
- Re: Memory leak when internal pointer passed out as parameter
- From: Daniel Rudy
- Memory leak when internal pointer passed out as parameter
- Prev by Date: Re: brain teasers
- Next by Date: Re: end in a loop
- Previous by thread: Re: Memory leak when internal pointer passed out as parameter
- Next by thread: Re: Memory leak when internal pointer passed out as parameter
- Index(es):
Relevant Pages
|