Siprj / mem-leak-checker

Small and fast tool for memory analysis (finding memory leaks). Because it is small and easy to cross compile you can use it for embedded systems.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mem-leak-checker

Mem-leak-checker is small library (library and program) which will looks for memory leaks in your program.

Why create new memory analysis tool

I started work on this project when I needed small and lock free memory analysis tool for embedded system I worked on at my job. This embedded system (ARMv5) was not able to run valgrind or memtrace or lots of other tools because application which was running on it took 90% of CPU time. Because there was not anything so small and fast. I decided to write my own tool. Tool which don't use mutexes and don't create giant backtraces.

Features

  • small
  • lock-free (in time of logging)
  • multi-platform (x86, ARM, ...)
  • easy to use
  • easy to compile

How to compile

Project is "powered" by autotools and you need tools: autotools and libtool. Ubuntu users can these tools install by command:

  apt-get install autoconf automake libtool

If you are building from repository you mast call reconfigure first:

  autoreconf -i

Then you need to run configure:

  ./configure
  # In case of cross compilation add --host parameter followed by crosscomiler
  ./configure --host=arm-linux-gnueabi

Finally we can make and install whole project:

  make
  make install

For more info how to compile with configure read:

How to use this library

Logging library can by used by setting up environment variable LD_PRELOAD. All programs started with this variable will load first libmalloc-lib and after then it will load everything else. That's the whole key of function. This way we can hook up all memory calls.

LD_PRELOAD=/path/to/lib/libmalloc-lib.so.x.x.x ./your-app

After finish of your app you will see two files:

  1. mem-leak-analysis.bin
  2. mem-leak-analysis-summary.txt

as the name suggests, these two files are outputs of analysis ;). But only one file will be used in next step. Because the second file stores only summary how much memory calls was done.

Postprocess

So let's go get our info from binary file. There is second part of tool called malloc-lib-postprocess and we can use it for getting all needed informations from bin file. Postprocess program has three parameters -a -f and -l. Parameter -a is path to debug app, parameter -f is path to binary file generated by analysis and parameter -l is addr2lin for given platform. So example could look like:

  ./malloc-lib-posprocess -a test-app -f mem-leak-analysis-sumary.txt -l addr2line

And output will be something like this:

*******************************************************
memory leak at address: 0x7ff8f8002250 size of memory leak: 48 bytes
return address: 0x40821c

system call: addr2line -e /.../build-mem-leak-checker-Desktop-Debug/test-app/test-app 0x40821c
/.../build-mem-leak-checker-Desktop-Debug/test-app/../../mem-leak-checker/test-app/main.cpp:38 (discriminator 1)

About

Small and fast tool for memory analysis (finding memory leaks). Because it is small and easy to cross compile you can use it for embedded systems.


Languages

Language:C++ 92.8%Language:C 6.1%Language:Shell 1.1%