Results 1 to 5 of 5

Thread: Memory leak Detection using Valgrind

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Memory leak Detection using Valgrind

    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,

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Re: Memory leak Detection using Valgrind

    Hey Joseph

    Did you put

    Qt Code:
    1. CONFIG += debug
    To copy to clipboard, switch view to plain text mode 

    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.

  3. #3
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Memory leak Detection using Valgrind

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Memory leak Detection using Valgrind

    You can use grep -v, if that's an option for you...

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Memory leak Detection using Valgrind

    you suppress those warnings/errors by using suppress files. You best generate those with the command switch --gen-suppressions.

    Qt Code:
    1. valgrind --tool=memcheck --leak-check=yes --gen-suppressions=yes ./yourapplication
    To copy to clipboard, switch view to plain text mode 
    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 Code:
    1. {
    2. Qt-Gui-getpwuid
    3. Memcheck:Leak
    4. fun:malloc
    5. obj:/lib/libc-2.6.1.so
    6. fun:__nss_database_lookup
    7. obj:*
    8. obj:*
    9. fun:getpwuid_r
    10. obj:/usr/lib/qt4/libQtGui.so.4.3.2
    11. obj:/usr/lib/qt4/libQtGui.so.4.3.2
    12. fun:_SmcProcessMessage
    13. fun:IceProcessMessages
    14. obj:/usr/lib/qt4/libQtGui.so.4.3.2
    15. obj:/usr/lib/qt4/libQtGui.so.4.3.2
    16. }
    To copy to clipboard, switch view to plain text mode 
    You then call your application with the suppress file provided as an argument:

    Qt Code:
    1. valgrind --tool=memcheck --leak-check=yes --suppressions=suppressfilexy.supp ./yourapplication
    To copy to clipboard, switch view to plain text mode 
    Be careful not to put error-reports belonging to your applictations code into the suppress file.

  6. The following user says thank you to momesana for this useful post:

    xavierda (6th June 2010)

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 22:38
  2. Qt4 & Visual Studio memory leak detection
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2008, 04:03
  3. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  4. Valgrind and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 12
    Last Post: 13th August 2007, 10:25
  5. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.