Checking for Memory Leaks with MemTrace


This package can be used to search for memory leaks in your program. It contains replacement functions for malloc() and free(). What makes this package different is that it uses Linux/x86-specific features to record a stack trace each time a memory chunk is allocated. Therefore, it can report precisely where a memory leak occured.

Unfortunately, this means that MemTrace is rather system dependant and may be impossible to use on other platforms than Linux/x86 and SunOS/Sparc. It has been tested with Linux 2.0.3x using binutils 2.9.1 and both libc5 and glibc2.

The package contains lots of borrowed code from glibc, binutils and gdb. Consequently, MemTrace itself is placed under the GNU General Public License (GPL).

It requires binutils to be installed. More specifically, it needs the include file <bfd.h> and the -lbfd library from the GNU binutils package (available on GNU mirror sites). The -liberty library is also needed, but it is usually installed along with gcc.

Example Output

#### Memory Usage Report
42 bytes allocated by f  (leak.c:21)
        called by main  (leak.c:40)
        called by _start
#### a total of 42 bytes allocated in 1 chunks


Frank Pilhofer <fp -AT- fpx.de> Back to the Homepage
Last modified: Sat Jun 9 21:05:19 2001