Re: Finding memory leak, walking the heap?



"Ed J" <jed@xxxxxxxxxxx> writes:

How can I embed checkpoints for memory leaks in my C++ code? I'm
looking for unfreed heap space allocated with "new" but not deleted,
and I would like to be able to ask for the current allocations in my
C++ code to help me pinpoint where the leak exists.

There are a smattering of diagnostic and debugging functions in the
glibc malloc library, which AFAIK is still used underneath operator
new. The numbers you want are in the "struct mallinfo" stats.

See the libc info pages for malloc:
http://www.gnu.org/software/libtool/manual/libc/Statistics-of-Malloc.html

If you want any more detail you'll probably need to implement a set of
hook functions, also as described in the manual.

--
Grant Taylor
Embedded Linux Consultant
http://www.picante.com/
.