LeakTracer - trace and analyze memory leaks in C++ programsOct 2011 UPDATE: Frédéric Germain has setup a Github page containing all the below patches and additional new features, see: https://github.com/fredericgermain/LeakTracer. This is the newest version; all the below source code and documentation are of historic interest only. LeakTracer is a small tool I wrote when checking a C++ program for memory leaks. I couldn't get dmalloc to display what I wanted, and I just saw the __builtin_return_address gcc-extension mentioned. To use LeakTracer, run your program using the provided LeakCheck script. It uses the LD_PRELOAD feature to "overlay" some functions on top of your functions (no recompile needed). If your platform does not support LD_PRELOAD, you can add the LeakTracer.o object file to the objects in your Makefile and run your application. LeakTracer uses gdb to print out the exact line where the memory was allocated and not freed - this of course means you have to free all dynamically allocated data. LeakTracer also overrides the global operator new and operator delete - this will give problems if you override them as well. LeakTracer traces only new/new[] and delete calls - it does not look at malloc/free/realloc. Read the full README file included in the package for more information.
AvailabilityLeakTracer source: ( 10K) v2.4 LeakTracer.tar.gz LeakTrace works on my Linux system and has been reported to work on Solaris as well as HP-UX. Because of its simplicity it has gained some surprising popularity and has seen use in e.g. KDE and Mozilla. License: Public Domain (do with it whatever you want). EXTENDED VERSION: Michael Gopshtein has completely rewritten LeakTracer to make it more efficient and flexible, monitor specific threads and display the ful stack trace. Download LeakTracer-mg.tar.gz. LeakTracer is now part of Debian (testing/unstable), just apt-get install leaktracer, courtesy of Yann Dirson. |
|
Sadly, time constraints have not yet permitted me to integrate these into the main LT package:
leaktracer-freestackopt.diff - submitted by Robin Hiroko Walsh of TextDigger, this patch optimises LeakTracer's freelist searching, improving performance 40-fold in certain cases.
Patch for capturing and presenting multiple stack levels by José María González: ( 12K) leaktracer.all.diff -- this includes many other features, see mail.txt.
TK front-end by Andrew Ogley: (2.7K) v2.2 LeakTool-1.1.tgz
Excel macro for presenting LT results by Amir Kirsh and Ido Zilbergled: ( 13K) OrganizeLeakTracerOutput.zip
ARM patch by Patrick: leaktracer-on-arm.diff
Patch for tracing malloc/free too by Greg Stewart: LeakTracer-mf.cc (save as LeakTracer.cc and add -ldl to libraries in Makefile)
Another patch from Боби Б. for MIPS support: LeakTracer-MIPS.patch.
~/p/arc# ea/LeakTracer/leak-analyze ./arc Gathered 8 (8 unique) points of data. (gdb) Allocations: 1 / Size: 36 0x80608e6 is in NullArcableInstance::NullArcableInstance(void) (Machine.cc:40). 39 public: 40 NullArcableInstance() : ArcableInstance(new NullArcable) {} |
February 23, 1999 v1.1 - first public release November 19, 2000 v2.0 - Rewrite by Henner Zeller introduces LD_PRELOAD and much more February 27, 2001 v2.1 - Further update by Henner: optional thread safety, choose what should make LeakTracer abort(), better tracing of delete on non-new'ed pointers August 28, 2003 v2.4 - Improve MAGIC on platforms that don't allow unaligned access