Leak Tracer vs valgrind for memory leak analysis of a C++ project

Attaching a large project to leak tracer is faster than valgrind.
How to use leaktracer and valgrind step by step:
A memory leaking program which would be used to check for memory leak using LeakTracer.
using namespace std;
int main()
char* name = new char[20];//allocates 20 bytes
//delete[] name;//Now leaks 20 byte
//sleep (30);
return 0;
------------------------STEPS to use LeakTracer----------

STEP-0: Compile with -g flag to capture gdb debugging symbols.
    g++ -g leakProgram.cpp
    Here "a.out" would be my application in which I want check memory leak

STEP-1: run command "LeakCheck" with your application, here a.out
    /usr/bin/LeakCheck /home/admin/a.out

STEP-2: run command "leak-analyze" with your application and generated file leak.out
    /usr/bin/leak-analyze a.out /home/admin/leak.out

Ubuntu:~/$ g++ -g leakProgram.cpp
Ubuntu:~/$ /usr/bin/LeakCheck /home/admin/a.out
Ubuntu:~/$ /usr/bin/leak-analyze a.out /home/admin/leak.out
Gathered 1 (1 unique) points of data.
Reading symbols from a.out...done.
#-- Leak: counted 1x / total Size: 20
0x80485c2 is in main() (leakProgram.cpp:6).
5    {
6    char* name = new char[20];//allocates 20 bytes but not freed.

--------------------STEPS to use Valigrind----------
Ubuntu:~$ valgrind --tool=memcheck --leak-check=yes ./a.out
==6829== Memcheck, a memory error detector
==6829== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==6829== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==6829== Command: ./a.out
==6829== HEAP SUMMARY:
==6829==     in use at exit: 20 bytes in 1 blocks
==6829==   total heap usage: 1 allocs, 0 frees, 20 bytes allocated
==6829== 20 bytes in 1 blocks are definitely lost in loss record 1 of 1
==6829==    at 0x402ADFC: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6829==    by 0x80485C1: main (leakProgram.cpp:6)
==6829== LEAK SUMMARY:
==6829==    definitely lost: 20 bytes in 1 blocks
==6829==    indirectly lost: 0 bytes in 0 blocks
==6829==      possibly lost: 0 bytes in 0 blocks
==6829==    still reachable: 0 bytes in 0 blocks
==6829==         suppressed: 0 bytes in 0 blocks
==6829== For counts of detected and suppressed errors, rerun with: -v
==6829== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

CMakeLists.txt and cmake interview questions

No comments:

Post a Comment