Tracking memory leaks..
Jeff Barr
jeff at amsdsg.UUCP
Fri Sep 9 22:52:24 AEST 1988
In article <3950011 at eecs.nwu.edu>, naim at eecs.nwu.edu (Naim Abdullah) writes:
> I want to check sections of a big program for memory leaks. My basic
> strategy was to define functions xmalloc() and xfree() that would keep
> track of the amount allocated, and to see if the amount went down to
> zero where it should (I wanted to use "#define malloc xmalloc" in the
> main header file to replace occurrences of malloc() and free()).
>
> The problem with this scheme is that I don't know how much space free()
> will actually free.
You can allocate space for an extra 'int' in xmalloc, store the size
yourself at the beginning of the allocated block (being sure to return a
pointer PAST the 'int'), and then retrieve it in xfree.
Jeff
+---------------------------------------------------------+
| Jeff Barr AMS-DSG uunet!amsdsg!jeff 800-832-8668 |
+---------------------------------------------------------+
--
Jeff
+---------------------------------------------------------+
| Jeff Barr AMS-DSG uunet!amsdsg!jeff 800-832-8668 |
+---------------------------------------------------------+
More information about the Comp.lang.c
mailing list