PDA

View Full Version : I have memory leak on every Qt3/4 application, Qt bug?



saugumas
14th November 2007, 18:20
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


#include "kdesimpleapp.h"
#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>

static const char description[] =
I18N_NOOP("A KDE KPart Application");

static const char version[] = "0.1";

static KCmdLineOptions options[] =
{
// { "+[URL]", I18N_NOOP( "Document to open" ), 0 },
KCmdLineLastOption
};

int main(int argc, char **argv)
{
KAboutData about("kdesimpleapp", I18N_NOOP("KDEsimpleapp"), version, description,
KAboutData::License_GPL, "(C) 2007 unknown,,,", 0, 0, "unknown@unknown");
about.addAuthor( "unknown,,,", 0, "unknown@unknown" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions( options );
KApplication app;
KDEsimpleapp *mainWin = 0;

if (app.isRestored())
{
RESTORE(KDEsimpleapp);
}
else
{
// no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

/// @todo do something with the command line args here

mainWin = new KDEsimpleapp();
app.setMainWidget( mainWin );
mainWin->show();

args->clear();
}

// mainWin has WDestructiveClose flag by default, so it will delete itself.
return app.exec();
}

kdesimpleapp.cpp

#include "kdesimpleapp.h"

#include <qlabel.h>

#include <kmainwindow.h>
#include <klocale.h>

KDEsimpleapp::KDEsimpleapp()
: KMainWindow( 0, "KDEsimpleapp" )
{
// set the shell's ui resource file
setXMLFile("kdesimpleappui.rc");

new QLabel( "Hello World", this, "hello label" );
}

KDEsimpleapp::~KDEsimpleapp()
{
}

#include "kdesimpleapp.moc"

kdesimpleapp.h

#ifndef _KDESIMPLEAPP_H_
#define _KDESIMPLEAPP_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kmainwindow.h>

/**
* @short Application Main Window
* @author unknown,,, <unknown@unknown>
* @version 0.1
*/
class KDEsimpleapp : public KMainWindow
{
Q_OBJECT
public:
/**
* Default Constructor
*/
KDEsimpleapp();

/**
* Default Destructor
*/
virtual ~KDEsimpleapp();
};

#endif // _KDESIMPLEAPP_H_

part of my valgrind output:

==23225== ERROR SUMMARY: 25 errors from 12 contexts (suppressed: 97 from 1)
==23225== malloc/free: in use at exit: 190,786 bytes in 2,530 blocks.
==23225== malloc/free: 137,830 allocs, 135,300 frees, 5,833,593 bytes allocated.
==23225== For counts of detected errors, rerun with: -v
==23225== searching for pointers to 2,530 not-freed blocks.
==23225== checked 1,115,428 bytes.
==23225==
==23225==
==23225== 38 bytes in 2 blocks are definitely lost in loss record 71 of 149
==23225== at 0x4022765: malloc (vg_replace_malloc.c:149)
==23225== by 0x4F848A7: FcStrCopy (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F87DEC: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x538E3D5: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x538F05C: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x539005D: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x5390FA4: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x538878A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.0.0)
==23225== by 0x4F86F0B: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F87205: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F87307: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F87771: (within /usr/lib/libfontconfig.so.1.2.0)
==23225==
==23225==
==23225== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 89 of 149
==23225== at 0x4022765: malloc (vg_replace_malloc.c:149)
==23225== by 0x531A9B2: (within /lib/tls/i686/cmov/libc-2.6.1.so)
==23225== by 0x531B208: __nss_database_lookup (in /lib/tls/i686/cmov/libc-2.6.1.so)
==23225== by 0x5855FDB: ???
==23225== by 0x585711C: ???
==23225== by 0x52C7EEB: getpwuid_r (in /lib/tls/i686/cmov/libc-2.6.1.so)
==23225== by 0x52C789D: getpwuid (in /lib/tls/i686/cmov/libc-2.6.1.so)
==23225== by 0x448853A: KStandardDirs::addCustomized(KConfig*) (in /usr/lib/libkdecore.so.4.2.0)
==23225== by 0x448E59C: KConfig::KConfig(QString const&, bool, bool, char const*) (in /usr/lib/libkdecore.so.4.2.0)
==23225== by 0x448EBBF: KSharedConfig::KSharedConfig(QString const&, bool, bool) (in /usr/lib/libkdecore.so.4.2.0)
==23225== by 0x448EDC0: KSharedConfig::openConfig(QString const&, bool, bool) (in /usr/lib/libkdecore.so.4.2.0)
==23225== by 0x448F14D: KInstance::config() const (in /usr/lib/libkdecore.so.4.2.0)
==23225==
==23225==
==23225== 316 (256 direct, 60 indirect) bytes in 2 blocks are definitely lost in loss record 109 of 149
==23225== at 0x4022765: malloc (vg_replace_malloc.c:149)
==23225== by 0x4F82363: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F82C63: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F82D67: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F87CD0: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x538E3D5: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x538F05C: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x539005D: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x5390FA4: (within /usr/lib/libexpat.so.1.0.0)
==23225== by 0x538878A: XML_ParseBuffer (in /usr/lib/libexpat.so.1.0.0)
==23225== by 0x4F86F0B: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F87205: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.2.0)
==23225==
==23225==
==23225== 2,224 (768 direct, 1,456 indirect) bytes in 2 blocks are definitely lost in loss record 138 of 149
==23225== at 0x4022862: realloc (vg_replace_malloc.c:306)
==23225== by 0x4F822A3: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F82C63: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F8315B: (within /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F7FA0F: FcFontRenderPrepare (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F7FBF7: FcFontSetMatch (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4F7FDA9: FcFontMatch (in /usr/lib/libfontconfig.so.1.2.0)
==23225== by 0x4EF2A3F: XftFontMatch (in /usr/lib/libXft.so.2.1.2)
==23225== by 0x492B66B: (within /usr/lib/libqt-mt.so.3.3.7)
==23225== by 0x4930E7C: QFontDatabase::findFont(QFont::Script, QFontPrivate const*, QFontDef const&, int) (in /usr/lib/libqt-mt.so.3.3.7)
==23225== by 0x48AC988: QFontPrivate::load(QFont::Script) (in /usr/lib/libqt-mt.so.3.3.7)
==23225== by 0xso.3.3.7)
==23225==
==23225== LEAK SUMMARY:
==23225== definitely lost: 1,098 bytes in 7 blocks.
==23225== indirectly lost: 1,636 bytes in 85 blocks.
==23225== possibly lost: 0 bytes in 0 blocks.
==23225== still reachable: 188,052 bytes in 2,438 blocks.
==23225== suppressed: 0 bytes in 0 blocks.
==23225== Reachable blocks (those to which a pointer was found) are not shown.
==23225== To see them, rerun with: --leak-check=full --show-reachable=yes

wysota
14th November 2007, 18:31
None of the leaks are caused by Qt but for example by fontconfig.

saugumas
14th November 2007, 19:02
few leaks are related to libqt-mt:

#
==23225== by 0x4930E7C: QFontDatabase::findFont(QFont::Script, QFontPrivate const*, QFontDef const&, int) (in /usr/lib/libqt-mt.so.3.3.7)
#
==23225== by 0x48AC988: QFontPrivate::load(QFont::Script) (in /usr/lib/libqt-mt.so.3.3.7)

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)

wysota
14th November 2007, 19:33
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.