documentation: find memory leak with glibc mtrace()

walter harms WHarms at bfs.de
Thu Feb 21 10:51:00 UTC 2008


Hi list,
we had recently a discussion about mem-bugs in ash. Because i am a heavy ash user
i tried to take a look into the problem. Not everyone is aware of all the
possibilities that lurk inside his system here is a short summary how to check
with the glibc mtrace() facility.

please add this to busybox.net.

re,
 wh




find memory leak with glibc mtrace()


The glibc has a facility to trace memory problems. It is called mtrace().
To make use of it you must call mtrace() as soon as possible in your
suspicious programm ( include <mcheck.h> ). You can use muntrace() to disable it.

Then compile busybox with debug enabled and make sure any optimisation is disabled as it will confuse the output.
you may like to try:
make V=1 and check the compiler flags

Now compile Busybox. For a special configuration you make use of the
KCONFIG_ALLCONFIG option for the make file.
Here are the steps:
* Generate a mini-config file with only the options you want
* do make allnoconfig KCONFIG_ALLCONFIG=my_mini_config

Before you start you programm you need to set e.g.

* export MALLOC_TRACE=./ash.mtrace

If you omitted that, no file will be produced !

now start your programm e.g.

* ./busybox_unstripped  ash

* mtrace ./busybox_unstripped ash.mtrace

This will show all unfreed mem and friends.
To learn more about mtrace read the glibc info pages.




More information about the busybox mailing list