PDA

View Full Version : Memory leak Detection using Valgrind



joseph
12th March 2008, 13:09
Hello

I am running my application on Open Suse10.2 and i am using "Valgrind"
to detect memory leaks in the program.

I want to know how to suppress the memory leaks created in the dynamically linked libraries,since i want to know precisely where my program is leaking rather than in the linked libraries.

Thank You,

pdoria
12th March 2008, 14:09
Hey Joseph

Did you put



CONFIG += debug


in your .pro file?

I also find using G_SLICE=always-malloc before the call to the program for debugging purposes. someting like this:

valgrind -v --leak-check=yes G_SLICE=always-malloc ./myapp

HTH,
Pedro.

joseph
13th March 2008, 11:21
When i run valgrind -v --leak-check=yes command, it gives me a very comprehensive list of memory leak errors mostly from the linked "LIBRARIES".I want to suppress these messages.I want to know only memory leaks caused in my code.
How to this suppress file?

wysota
13th March 2008, 15:37
You can use grep -v, if that's an option for you...

momesana
27th March 2008, 07:34
you suppress those warnings/errors by using suppress files. You best generate those with the command switch --gen-suppressions.



valgrind --tool=memcheck --leak-check=yes --gen-suppressions=yes ./yourapplication
You then copy paste the suppressions into a file, give them appropriate names and use that file with the --suppressions switch when debugging your application.
A suppress statement may look like this:


{
Qt-Gui-getpwuid
Memcheck:Leak
fun:malloc
obj:/lib/libc-2.6.1.so
fun:__nss_database_lookup
obj:*
obj:*
fun:getpwuid_r
obj:/usr/lib/qt4/libQtGui.so.4.3.2
obj:/usr/lib/qt4/libQtGui.so.4.3.2
fun:_SmcProcessMessage
fun:IceProcessMessages
obj:/usr/lib/qt4/libQtGui.so.4.3.2
obj:/usr/lib/qt4/libQtGui.so.4.3.2
}

You then call your application with the suppress file provided as an argument:



valgrind --tool=memcheck --leak-check=yes --suppressions=suppressfilexy.supp ./yourapplication
Be careful not to put error-reports belonging to your applictations code into the suppress file.