[OS]/Embedded&Linux

LeakTracer - trace and analyze memory leaks in C++ programs

하늘을닮은호수M 2007. 10. 11. 15:22
반응형

LeakTracer - trace and analyze memory leaks in C++ programs

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.

Availability

LeakTracer 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.

What's new
Nov 16A few user contributions to LeakTracer
Sep 19The wonderful world of CSS
Feb 13New XEmacs elisp -- C/C++ utilities

Site navigation


External links for this page
ccmalloc - Shows full function traceback
valgrind - powerful tool combines strace/efence/leak tracing

Version history

February 23, 1999               v1.1 - first public releaseNovember 19, 2000               v2.0 - Rewrite by Henner Zeller introduces LD_PRELOAD                                       and much moreFebruary 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 pointersAugust 28, 2003                 v2.4 - Improve MAGIC on platforms that don't allow unaligned                                       access

If you have a page for your project where you describe how you successfully used LeakTracer, do not hesitate to email me.

User Contributions

Sadly, time constraints have not yet permitted me to integrate these into the main LT package:

Patch for capturing and presenting multiple stack levels by JosarGonzz: ( 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)

Example output

~/p/arc# ea/LeakTracer/leak-analyze ./arcGathered 8 (8 unique) points of data.(gdb)Allocations: 1 / Size: 360x80608e6 is in NullArcableInstance::NullArcableInstance(void) (Machine.cc:40).39      public:40          NullArcableInstance() : ArcableInstance(new NullArcable) {}

Allocations: 1 / Size: 80x8055b02 is in init_types(void) (Type.cc:119).118 void init_types() {119 Type::Integer = new IntegerType;

Allocations: 1 / Size: 132 (new[])0x805f4ab is in Hashtable::Hashtable(unsigned int) (ea/h/Hashtable.h:15).14 Hashtable (uint _size = 32) : size(_size), count(0) {15 table = new List [size];

반응형