Re: malloc and realloc



Yevgen Muntyan wrote:
santosh wrote:
tphipps@xxxxxxxxxxxxxx wrote:
At the risk of repeating myself...

On Jan 28, 4:20 pm, CBFalconer <cbfalco...@xxxxxxxxx> wrote:
<snip>

Any time you see "x =realloc(x, size);" you have a potential
memory leak, and you know the coder is probably inexperienced.
Exceptions exist.
So there's a memory leak for some tiny number of clock cycles until
abort() is called... big deal.

Some primitive systems are unable to reclaim memory lost through a
program leak. DOS and Windows 3.x series were famous for this feature.
IIRC, even Windows 95 occasionally suffered from this deficiency.

In those cases abort() call is the problem, not that single leak,
since all memory allocated elsewhere isn't freed, right?

Yes. That's why it's good practise to release resources after you've
used it.

Should a program never call abort() ?

It's fine during development and debugging, but during actual use, in
most cases, you can shut down far more gracefully than abort()ing.

How about exit(EXIT_FAILURE) and such?

Better, but still, the fact remains that he hasn't explicitly
free()'ed the memory he allocated, thus setting up a potential memory
leak.

Anyway, it was about "memory leak for some tiny number of clock cycles"
which indeed is that - a "leak" that nobody can even notice.

Except on the above mentioned systems.

.



Relevant Pages

  • Re: How important is it to handle Memory Leaks
    ... In my program I am displaying some pattern on the ... 'Memory DC' inside those functions...and use it to just BitBlt to the main ... window when ever windows generates WM_PAINT. ... > it will cause leak if some other programmer enhances your program. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: MDAC memory leak
    ... Most libraries place the decision of when to free ... There's a capability of breaking on a particular memory allocation, ... leak 500 objects, on the second test I leak 3, because I fixed the bug). ... "App shows memory leak on some machines." ...
    (microsoft.public.vc.mfc)
  • Re: Can an application hang Windows 2000?
    ... > upgrade, two of these PCs have hung, one after approx. ... The operating system is Windows 2000. ... The obvious question in mind is to look for a memory leak. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: MDAC memory leak
    ... Also when we used some of the memory leak tools suggested on microsoft site ... A mutex is a considerably less efficient synchronization ... "App shows memory leak on some machines." ...
    (microsoft.public.vc.mfc)
  • Re: Memory leak in the Driver
    ... Paul G. Tobey wrote: ... driver development, it's most likely that you are at fault. ... The QFE has no impact on the leak but one thing is sure, ... i am sure that all the memory that i am allocating in my driver is ...
    (microsoft.public.windowsce.platbuilder)