If you are a Developer / QA engineer, you may need to check for memory leaks before field use of your product. Though there are some licensed tools for memory leak, however you can make use of valgrind if you are using unix/linux as development environment. The commands explained below are being used in Ubuntu 12.04 LTS systems.
- Install libc6 package as described in below step.
- If your machine is 64 bit, and you want to use valgrind for 32 bit executables use below command.apt-get install libc6-dbg:i386
If your machine is 64 bit, and you want to use valgrind for 64 bit executables use below command.apt-get install libc6-dbg
- To check memory leak start executable with below commandvalgrind --tool=memcheck --leak-check=yes --log-file=/log/file/path/filename ./your-executable
- Use --track-origins=yes option to find the origins of undefined values
If you want to install latest valgrind, download the source code from here.
Then follow follow below step to compile and install it. For more options please check readme / install files.
sed -i 's|/doc/valgrind||' docs/Makefile.in
./configure --prefix=/usr --datadir=/usr/share/doc/valgrind-3.10.1