Results 1 to 4 of 4

Thread: I have memory leak on every Qt3/4 application, Qt bug?

  1. #1
    Join Date
    Nov 2007
    Location
    Lithuania
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Exclamation I have memory leak on every Qt3/4 application, Qt bug?

    Hello, I experience problem,:
    When I create project from Kdevelop template(for example KDE "Hello world") and run untouched program with valgrind I get leaks!

    I use Kdevlop 3.5.0.1 (2007-October-24 - Third binary snapshot of the stable KDevelop 3.5.x release series) on Kubuntu 7.10


    code is untouched after generated with new project template

    main.cpp
    Qt Code:
    1. #include "kdesimpleapp.h"
    2. #include <kapplication.h>
    3. #include <kaboutdata.h>
    4. #include <kcmdlineargs.h>
    5. #include <klocale.h>
    6.  
    7. static const char description[] =
    8. I18N_NOOP("A KDE KPart Application");
    9.  
    10. static const char version[] = "0.1";
    11.  
    12. static KCmdLineOptions options[] =
    13. {
    14. // { "+[URL]", I18N_NOOP( "Document to open" ), 0 },
    15. KCmdLineLastOption
    16. };
    17.  
    18. int main(int argc, char **argv)
    19. {
    20. KAboutData about("kdesimpleapp", I18N_NOOP("KDEsimpleapp"), version, description,
    21. KAboutData::License_GPL, "(C) 2007 unknown,,,", 0, 0, "unknown@unknown");
    22. about.addAuthor( "unknown,,,", 0, "unknown@unknown" );
    23. KCmdLineArgs::init(argc, argv, &about);
    24. KCmdLineArgs::addCmdLineOptions( options );
    25. KApplication app;
    26. KDEsimpleapp *mainWin = 0;
    27.  
    28. if (app.isRestored())
    29. {
    30. RESTORE(KDEsimpleapp);
    31. }
    32. else
    33. {
    34. // no session.. just start up normally
    35. KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    36.  
    37. /// @todo do something with the command line args here
    38.  
    39. mainWin = new KDEsimpleapp();
    40. app.setMainWidget( mainWin );
    41. mainWin->show();
    42.  
    43. args->clear();
    44. }
    45.  
    46. // mainWin has WDestructiveClose flag by default, so it will delete itself.
    47. return app.exec();
    48. }
    To copy to clipboard, switch view to plain text mode 

    kdesimpleapp.cpp
    Qt Code:
    1. #include "kdesimpleapp.h"
    2.  
    3. #include <qlabel.h>
    4.  
    5. #include <kmainwindow.h>
    6. #include <klocale.h>
    7.  
    8. KDEsimpleapp::KDEsimpleapp()
    9. : KMainWindow( 0, "KDEsimpleapp" )
    10. {
    11. // set the shell's ui resource file
    12. setXMLFile("kdesimpleappui.rc");
    13.  
    14. new QLabel( "Hello World", this, "hello label" );
    15. }
    16.  
    17. KDEsimpleapp::~KDEsimpleapp()
    18. {
    19. }
    20.  
    21. #include "kdesimpleapp.moc"
    To copy to clipboard, switch view to plain text mode 

    kdesimpleapp.h
    Qt Code:
    1. #ifndef _KDESIMPLEAPP_H_
    2. #define _KDESIMPLEAPP_H_
    3.  
    4. #ifdef HAVE_CONFIG_H
    5. #include <config.h>
    6. #endif
    7.  
    8. #include <kmainwindow.h>
    9.  
    10. /**
    11.  * @short Application Main Window
    12.  * @author unknown,,, <unknown@unknown>
    13.  * @version 0.1
    14.  */
    15. class KDEsimpleapp : public KMainWindow
    16. {
    17. Q_OBJECT
    18. public:
    19. /**
    20.   * Default Constructor
    21.   */
    22. KDEsimpleapp();
    23.  
    24. /**
    25.   * Default Destructor
    26.   */
    27. virtual ~KDEsimpleapp();
    28. };
    29.  
    30. #endif // _KDESIMPLEAPP_H_
    To copy to clipboard, switch view to plain text mode 

    part of my valgrind output:
    Qt Code:
    1. ==23225== ERROR SUMMARY: 25 errors from 12 contexts (suppressed: 97 from 1)
    2. ==23225== malloc/free: in use at exit: 190,786 bytes in 2,530 blocks.
    3. ==23225== malloc/free: 137,830 allocs, 135,300 frees, 5,833,593 bytes allocated.
    4. ==23225== For counts of detected errors, rerun with: -v
    5. ==23225== searching for pointers to 2,530 not-freed blocks.
    6. ==23225== checked 1,115,428 bytes.
    7. ==23225==
    8. ==23225==
    9. ==23225== 38 bytes in 2 blocks are definitely lost in loss record 71 of 149
    10. ==23225== at 0x4022765: malloc (vg_replace_malloc.c:149)
    11. ==23225== by 0x4F848A7: FcStrCopy (in /usr/lib/libfontconfig.so.1.2.0)
    12. ==23225== by 0x4F87DEC: (within /usr/lib/libfontconfig.so.1.2.0)
    13. ==23225== by 0x538E3D5: (within /usr/lib/libexpat.so.1.0.0)
    14. ==23225== by 0x538F05C: (within /usr/lib/libexpat.so.1.0.0)
    15. ==23225== by 0x539005D: (within /usr/lib/libexpat.so.1.0.0)
    16. ==23225== by 0x5390FA4: (within /usr/lib/libexpat.so.1.0.0)
    17. ==23225== by 0x538878A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.0.0)
    18. ==23225== by 0x4F86F0B: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
    19. ==23225== by 0x4F87205: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
    20. ==23225== by 0x4F87307: (within /usr/lib/libfontconfig.so.1.2.0)
    21. ==23225== by 0x4F87771: (within /usr/lib/libfontconfig.so.1.2.0)
    22. ==23225==
    23. ==23225==
    24. ==23225== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 89 of 149
    25. ==23225== at 0x4022765: malloc (vg_replace_malloc.c:149)
    26. ==23225== by 0x531A9B2: (within /lib/tls/i686/cmov/libc-2.6.1.so)
    27. ==23225== by 0x531B208: __nss_database_lookup (in /lib/tls/i686/cmov/libc-2.6.1.so)
    28. ==23225== by 0x5855FDB: ???
    29. ==23225== by 0x585711C: ???
    30. ==23225== by 0x52C7EEB: getpwuid_r (in /lib/tls/i686/cmov/libc-2.6.1.so)
    31. ==23225== by 0x52C789D: getpwuid (in /lib/tls/i686/cmov/libc-2.6.1.so)
    32. ==23225== by 0x448853A: KStandardDirs::addCustomized(KConfig*) (in /usr/lib/libkdecore.so.4.2.0)
    33. ==23225== by 0x448E59C: KConfig::KConfig(QString const&, bool, bool, char const*) (in /usr/lib/libkdecore.so.4.2.0)
    34. ==23225== by 0x448EBBF: KSharedConfig::KSharedConfig(QString const&, bool, bool) (in /usr/lib/libkdecore.so.4.2.0)
    35. ==23225== by 0x448EDC0: KSharedConfig::openConfig(QString const&, bool, bool) (in /usr/lib/libkdecore.so.4.2.0)
    36. ==23225== by 0x448F14D: KInstance::config() const (in /usr/lib/libkdecore.so.4.2.0)
    37. ==23225==
    38. ==23225==
    39. ==23225== 316 (256 direct, 60 indirect) bytes in 2 blocks are definitely lost in loss record 109 of 149
    40. ==23225== at 0x4022765: malloc (vg_replace_malloc.c:149)
    41. ==23225== by 0x4F82363: (within /usr/lib/libfontconfig.so.1.2.0)
    42. ==23225== by 0x4F82C63: (within /usr/lib/libfontconfig.so.1.2.0)
    43. ==23225== by 0x4F82D67: (within /usr/lib/libfontconfig.so.1.2.0)
    44. ==23225== by 0x4F87CD0: (within /usr/lib/libfontconfig.so.1.2.0)
    45. ==23225== by 0x538E3D5: (within /usr/lib/libexpat.so.1.0.0)
    46. ==23225== by 0x538F05C: (within /usr/lib/libexpat.so.1.0.0)
    47. ==23225== by 0x539005D: (within /usr/lib/libexpat.so.1.0.0)
    48. ==23225== by 0x5390FA4: (within /usr/lib/libexpat.so.1.0.0)
    49. ==23225== by 0x538878A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.0.0)
    50. ==23225== by 0x4F86F0B: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
    51. ==23225== by 0x4F87205: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
    52. ==23225==
    53. ==23225==
    54. ==23225== 2,224 (768 direct, 1,456 indirect) bytes in 2 blocks are definitely lost in loss record 138 of 149
    55. ==23225== at 0x4022862: realloc (vg_replace_malloc.c:306)
    56. ==23225== by 0x4F822A3: (within /usr/lib/libfontconfig.so.1.2.0)
    57. ==23225== by 0x4F82C63: (within /usr/lib/libfontconfig.so.1.2.0)
    58. ==23225== by 0x4F8315B: (within /usr/lib/libfontconfig.so.1.2.0)
    59. ==23225== by 0x4F7FA0F: FcFontRenderPrepare (in /usr/lib/libfontconfig.so.1.2.0)
    60. ==23225== by 0x4F7FBF7: FcFontSetMatch (in /usr/lib/libfontconfig.so.1.2.0)
    61. ==23225== by 0x4F7FDA9: FcFontMatch (in /usr/lib/libfontconfig.so.1.2.0)
    62. ==23225== by 0x4EF2A3F: XftFontMatch (in /usr/lib/libXft.so.2.1.2)
    63. ==23225== by 0x492B66B: (within /usr/lib/libqt-mt.so.3.3.7)
    64. ==23225== by 0x4930E7C: QFontDatabase::findFont(QFont::Script, QFontPrivate const*, QFontDef const&, int) (in /usr/lib/libqt-mt.so.3.3.7)
    65. ==23225== by 0x48AC988: QFontPrivate::load(QFont::Script) (in /usr/lib/libqt-mt.so.3.3.7)
    66. ==23225== by 0xso.3.3.7)
    67. ==23225==
    68. ==23225== LEAK SUMMARY:
    69. ==23225== definitely lost: 1,098 bytes in 7 blocks.
    70. ==23225== indirectly lost: 1,636 bytes in 85 blocks.
    71. ==23225== possibly lost: 0 bytes in 0 blocks.
    72. ==23225== still reachable: 188,052 bytes in 2,438 blocks.
    73. ==23225== suppressed: 0 bytes in 0 blocks.
    74. ==23225== Reachable blocks (those to which a pointer was found) are not shown.
    75. ==23225== To see them, rerun with: --leak-check=full --show-reachable=yes
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: I have memory leak on every Qt3/4 application, Qt bug?

    None of the leaks are caused by Qt but for example by fontconfig.

  3. #3
    Join Date
    Nov 2007
    Location
    Lithuania
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: I have memory leak on every Qt3/4 application, Qt bug?

    few leaks are related to libqt-mt:
    Qt Code:
    1. #
    2. ==23225== by 0x4930E7C: QFontDatabase::findFont(QFont::Script, QFontPrivate const*, QFontDef const&, int) (in /usr/lib/libqt-mt.so.3.3.7)
    3. #
    4. ==23225== by 0x48AC988: QFontPrivate::load(QFont::Script) (in /usr/lib/libqt-mt.so.3.3.7)
    To copy to clipboard, switch view to plain text mode 

    but I noticed other strange thing:
    I checked some KDE apps, and every app I checked have small leaks(form various fonts libraries, X11 libraries, KDE libraries, is it normal to linux or it's KDE/Qt related problem? (i used windows before)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: I have memory leak on every Qt3/4 application, Qt bug?

    Quote Originally Posted by saugumas View Post
    few leaks are related to libqt-mt:
    No, they are not. If you make a function that leaks memory and I call your function, the leak is in your function, not mine. Look that fontconfig is being called from the function you quote. I'm sure Qt has no memory leaks - Qt devs are very cautious about it.

    I checked some KDE apps, and every app I checked have small leaks(form various fonts libraries, X11 libraries, KDE libraries, is it normal to linux or it's KDE/Qt related problem? (i used windows before)
    Dependencies' devs don't tend to be as cautious about memory leaks as Qt devs. Qt has nothing to do with it. How is it in KDE, I don't know.

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 22:38
  2. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 16:24
  3. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 14:18
  4. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  5. 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.