Results 1 to 13 of 13

Thread: Valgrind and Memory leak

  1. #1
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Valgrind and Memory leak

    I need to check the leaks in my application.I am using valgrind for this purpose.I hav deleted all objects that are created using new operator.I had used setWindowIcon() to set
    the ICon for the main window.When i commented the statement there is a decrease in the
    --definitely lost row of valgrind. Any reason why there is decrease in this row.Can anybody
    suggest places where actually memory leaks occur.

  2. #2
    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: Valgrind and Memory leak

    Isn't this a double thread?

    If not, are you sure the leak actually occurs? Qt doesn't cause any memory leaks on its own, Trolltech puts much effort to assure that. If you really have a leak, it might be caused by the platform itself.

  3. #3
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Valgrind and Memory leak

    Any idea of platform leaks???

  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: Valgrind and Memory leak

    Did you check that you actually have a leak?

  5. #5
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Valgrind and Memory leak

    This is the Leak summary i am gettting when i run my application using valgrind:
    definitely lost:5689b in 118 blocks
    possibly lost:0 b in 0 blocks
    still reachable:295030b in 927 blocks
    supressed:0 byts in 0 blocks

    Can suggest wer actually leak is there..some lines from valgrind log

    ---QDialog::done(int)
    QDialog::accept()
    QMyDialog::closeEvent(QCloseEvent *)
    QWidget::event(QEvent *)

  6. #6
    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: Valgrind and Memory leak

    Did you use --leak-check=full --leak-resolution=high and --show-reachable=yes Valgrind options?

  7. #7
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Valgrind and Memory leak

    These are the options i have used:
    valgrind -v --show-reachable=no --leak-check=full --run-libc-freeres=yes
    When i commented the setWindowIcon() there is decrease in definitely lost row.

  8. #8
    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: Valgrind and Memory leak

    So please use the options I gave you. You'll get information about each potential leak. Then you'll be able to see if the leak comes from Qt or not.

  9. #9
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Valgrind and Memory leak

    This some sample output from Valgrind:

    Invalid read of size 4
    at 0x4010DD3: (within /lib/ld-2.3.6.so)
    by 0x4005F5B: (within /lib/ld-2.3.6.so)
    by 0x4006431: (within /lib/ld-2.3.6.so)
    by 0x4006A51: (within /lib/ld-2.3.6.so)
    by 0x400A1F6: (within /lib/ld-2.3.6.so)
    by 0x400B44E: (within /lib/ld-2.3.6.so)
    by 0x400A3CA: (within /lib/ld-2.3.6.so)
    by 0x43593D4: (within /lib/tls/i686/cmov/libc-2.3.6.so)

    ==5025== Address 0x43F1ED8 is 32 bytes inside a block of size 34 alloc'd
    ==5025== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
    ==5025== by 0x4005DA5: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4005EE5: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4006431: (within /lib/ld-2.3.6.so)
    ==5025== by 0x43593D4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025==
    ==5025== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
    ==5025== by 0x400B540: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4006DAF: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400A1F6: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400A3CA: (within /lib/ld-2.3.6.so)
    ==5025== by 0x43593D4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025==
    ==5025== Conditional jump or move depends on uninitialised value(s)
    ==5025== at 0x4010E21: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4359072: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x412ED20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x85DD0A6: QLibraryPrivate::load_sys() (in /home/SourceCode/myFile)
    ==5025== by 0x85D83D3: QLibraryPrivate::load() (in /home/SourceCode/myFile)
    ==5025== by 0x85D86B0: QLibraryPrivate::loadPlugin() (in /home/SourceCode/myFile)
    ==5025== by 0x85D4719: QFactoryLoader::instance(QString const&) const (in /home/SourceCode/myFile)
    ==5025== by 0x80EF9A0: createReadHandler(QIODevice*, QByteArray const&) (in /home/SourceCode/myFile)
    ==5025== by 0x80F0F29: QImageReaderPrivate::initHandler() (in /home/SourceCode/myFile)
    ==5025==
    ==5025== Conditional jump or move depends on uninitialised value(s)
    ==5025== at 0x4010E2C: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4359072: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x412ED20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x85DD0A6: QLibraryPrivate::load_sys() (in /home/SourceCode/myFile)
    ==5025== by 0x85D83D3: QLibraryPrivate::load() (in /home/SourceCode/myFile)
    ==5025== by 0x85D86B0: QLibraryPrivate::loadPlugin() (in /home/SourceCode/myFile)
    ==5025== by 0x85D4719: QFactoryLoader::instance(QString const&) const (in /home/SourceCode/myFile)
    ==5025== by 0x80EF9A0: createReadHandler(QIODevice*, QByteArray const&) (in /home/SourceCode/myFile)
    ==5025== by 0x80F0F29: QImageReaderPrivate::initHandler() (in /home/SourceCode/myFile)
    ==5025==
    ==5025== Conditional jump or move depends on uninitialised value(s)
    ==5025== at 0x4010D14: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4006704: (within /lib/ld-2.3.6.so)
    ==5025== by 0x435936F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x412ED20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x85DD0A6: QLibraryPrivate::load_sys() (in /home/SourceCode/myFile)
    ==5025== by 0x85D83D3: QLibraryPrivate::load() (in /home/SourceCode/myFile)
    ==5025== by 0x85D86B0: QLibraryPrivate::loadPlugin() (in /home/SourceCode/myFile)
    ==5025==
    ==5025== Conditional jump or move depends on uninitialised value(s)
    ==5025== at 0x4010E2C: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4006704: (within /lib/ld-2.3.6.so)
    ==5025== by 0x435936F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x412ED20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x85DD0A6: QLibraryPrivate::load_sys() (in /home/SourceCode/myFile)
    ==5025== by 0x85D83D3: QLibraryPrivate::load() (in /home/SourceCode/myFile)
    ==5025== by 0x85D86B0: QLibraryPrivate::loadPlugin() (in /home/SourceCode/myFile)
    ==5025==
    ==5025== Conditional jump or move depends on uninitialised value(s)
    ==5025== at 0x4010E2C: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4004B78: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4006792: (within /lib/ld-2.3.6.so)
    ==5025== by 0x435936F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x412ED20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x85DD0A6: QLibraryPrivate::load_sys() (in /home/SourceCode/myFile)
    ==5025== by 0x85D83D3: QLibraryPrivate::load() (in /home/SourceCode/myFile)
    ==5025==
    ==5025== Invalid read of size 4
    ==5025== at 0x4010E00: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4004B78: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4006792: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400A1F6: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400A3CA: (within /lib/ld-2.3.6.so)
    ==5025== by 0x43593D4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== Address 0x4473950 is 24 bytes inside a block of size 25 alloc'd
    ==5025== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
    ==5025== by 0x4006B83: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400A1F6: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x400A3CA: (within /lib/ld-2.3.6.so)
    ==5025== by 0x43593D4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x4358DDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
    ==5025== by 0x412ED8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x400B44E: (within /lib/ld-2.3.6.so)
    ==5025== by 0x412F42C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025== by 0x412ED20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
    ==5025==
    ==5025== Syscall param write(buf) points to uninitialised byte(s)
    ==5025== at 0x4000792: (within /lib/ld-2.3.6.so)
    ==5025== by 0x407229E: _X11TransWrite (in /usr/lib/libX11.so.6.2.0)
    ==5025== by 0x4077BD5: (within /usr/lib/libX11.so.6.2.0)
    ==5025== by 0x4077CAA: _XReply (in /usr/lib/libX11.so.6.2.0)
    ==5025== by 0x405DF70: XInternAtom (in /usr/lib/libX11.so.6.2.0)
    ==5025== by 0x4071DCA: XSetWMProperties (in /usr/lib/libX11.so.6.2.0)
    ==5025== by 0x80D4DB6: QWidgetPrivate::create_sys(unsigned long, bool, bool) (in /home/SourceCode/myFile)
    ==5025== by 0x80ABF2E: QWidget::create(unsigned long, bool, bool) (in /home/SourceCode/myFile)
    ==5025== by 0x80ACEC9: QWidgetPrivate::createWinId(unsigned long) (in /home/SourceCode/myFile)
    ==5025== by 0x80ACFC2: QWidgetPrivate::setWindowTitle_helper(QString const&) (in /home/SourceCode/myFile)
    ==5025== by 0x80AD2F6: QWidget::setWindowTitle(QString const&) (in /home/SourceCode/myFile)
    ==5025== by 0x8069955: myClass::myClass() (in /home/SourceCode/myFile)
    ==5025== Address 0x446B9F8 is 192 bytes inside a block of size 16,384 alloc'd
    ==5025== at 0x401C7EF: calloc (vg_replace_malloc.c:279)
    ==5025== by 0x4062CBD: XOpenDisplay (in /usr/lib/libX11.so.6.2.0)
    ==5025== by 0x80C00E3: qt_init(QApplicationPrivate*, int, _XDisplay*, unsigned long, unsigned long) (in /home/SourceCode/myFile)
    ==5025== by 0x807CCF8: QApplicationPrivate::construct(_XDisplay*, unsigned long, unsigned long) (in /home/SourceCode/myFile)
    ==5025== by 0x807DABD: QApplication::QApplication(int&, char**, int) (in /home/SourceCode/myFile)
    ==5025== by 0x806EC19: main (in /home/SourceCode/myFile)

    ==5025== LEAK SUMMARY:
    ==5025== definitely lost: 5,689 bytes in 118 blocks.
    ==5025== possibly lost: 0 bytes in 0 blocks.
    ==5025== still reachable: 295,030 bytes in 927 blocks.
    ==5025== suppressed: 0 bytes in 0 blocks.

    i hav tried the option posted by you.This is the result shown by valgrind
    Last edited by Krish_ng; 10th August 2007 at 13:24. Reason: adding leak summary

  10. #10
    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: Valgrind and Memory leak

    I don't see any leak reports here. Did you compile with debug information (like -g option to g++)? A leak report should be something like the following:

    ==9626== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
    ==9626== at 0x401F91C: operator new[](unsigned) (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
    ==9626== by 0x8048460: main (t.cpp:5)
    Anyway you can see in your report that most of the notes are caused by libc, libdl and your code.

  11. #11
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Valgrind and Memory leak

    ==5025== LEAK SUMMARY:
    ==5025== definitely lost: 5,689 bytes in 118 blocks.
    ==5025== possibly lost: 0 bytes in 0 blocks.
    ==5025== still reachable: 295,030 bytes in 927 blocks.
    ==5025== suppressed: 0 bytes in 0 blocks.

    Then wat this leak summary says...Does it mean leak is there...I hav not tried debug option.Any idea??

  12. #12
    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: Valgrind and Memory leak

    Try compiling with debug information so that valgrind can trace function calls. Anyway I don't think there is a leak in Qt (based on this report you pasted). I suggest you correct the things pointed out in your code though.

  13. #13
    Join Date
    Jul 2007
    Posts
    57
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Valgrind and Memory leak

    I hav to try with debug..If the leak is not from Qt it should be from my appliction..The leak summary gives some leakage..

Similar Threads

  1. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 12:47

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.