balancing free() and malloc()

roger.h.levy rl at cbnewsl.att.com
Sun Jun 23 03:36:09 AEST 1991


Is there a reasonable way to determine if all malloc's in a program
are balanced by free's?  Since free() doesn't have a return value,
it may not be clear in complex pointer manipulation situations that
it's even been passed a pointer that points at dynamic memory.  I was
a little encouraged to see a function called coreleft() in Turbo C.
I hoped that by sprinking my program with this function, I could
audit the use of dynamic memory, but after some experimentation, I'm
not certain what this function really reports.  It may be reporting
the largest available block but that prevents me from accurately seeing
available memory shrink and grow.  My need is to verify that an
embedded systems controller won't slowly leak memory over a long
haul but I can do unit testing in a UNIX or PC environment.

Roger Levy
rl at groucho.att.com



More information about the Comp.lang.c mailing list