[Qt-interest] memory leak in Qt plugin system?
Thiago Macieira
thiago at kde.org
Thu Oct 1 10:59:22 CEST 2009
Em Quinta-feira 01 Outubro 2009, às 08:13:13, você escreveu:
> I think there is a memory leak in Qt plugin system. This leak
> can't be easily produced by the following code:
>
> #include <QtGui/QApplication>
> #include <QtGui/QWidget>
> #include <QtGui/QImageReader>
>
> int main(int argc, char *argv[])
> {
> QApplication a(argc, argv);
>
> QWidget w;
> w.show();
>
> QList<QByteArray> fmt = QImageReader::supportedImageFormats();
>
> int ret = a.exec();
>
> // Get the current bits
> int tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
> tmp |= _CRTDBG_LEAK_CHECK_DF;
> // Set the new bits
> _CrtSetDbgFlag(tmp);
>
> return ret;
> }
>
> if you have a windows system and build a debug version of the
> above program with visual studio, the memory leak will be reported in
> visual studio's output window after you exit the program (you must
> press F5 to start the program).
> The memory leak is caused by the line:
> QList<QByteArray> fmt = QImageReader::supportedImageFormats();
> this line will search all the image plugins and load them to
> collect supported image formats. For each plugin it will create a root
> component of the plugin and after collected information from this root
> component it will leave it undeleted. This behaviour is not the reason
> of the memory leak because according to Qt's manual "When the library
> is finally unloaded, the root component will automatically be
> deleted". But the fact is that even after the plugin dll is unloaded
> from the current process the root component is not deleted at all. And
> this leak will be detected by debug version of C runtime library as
> the above program showed to us.
Sorry, I cannot reproduce on Linux with valgrind. I don't think it's a leak.
==23801== Memcheck, a memory error detector.
==23801== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==23801== Using LibVEX rev 1884, a library for dynamic binary translation.
==23801== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==23801== Using valgrind-3.4.1, a dynamic binary instrumentation framework.
==23801== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==23801== For more details, rerun with: -v
==23801==
==23801==
==23801== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 164 from 2)
==23801== malloc/free: in use at exit: 136,061 bytes in 1,801 blocks.
==23801== malloc/free: 43,337 allocs, 41,536 frees, 5,316,273 bytes allocated.
==23801== For counts of detected errors, rerun with: -v
==23801== searching for pointers to 1,801 not-freed blocks.
==23801== checked 837,776 bytes.
==23801==
==23801== 148 (128 direct, 20 indirect) bytes in 1 blocks are definitely lost
in loss record 46 of 93
==23801== at 0x4025F1D: malloc (vg_replace_malloc.c:207)
==23801== by 0x545BD33: (within /usr/lib/libfontconfig.so.1.4.1)
==23801== by 0x545C89D: (within /usr/lib/libfontconfig.so.1.4.1)
==23801== by 0x545C9C4: (within /usr/lib/libfontconfig.so.1.4.1)
==23801== by 0x5460876: (within /usr/lib/libfontconfig.so.1.4.1)
==23801== by 0x54616ED: (within /usr/lib/libfontconfig.so.1.4.1)
==23801== by 0xBEC6315B: ???
==23801== by 0x12: ???
==23801== by 0xF: ???
==23801== by 0xE: ???
==23801==
==23801==
==23801== 420 (28 direct, 392 indirect) bytes in 1 blocks are definitely lost
in loss record 52 of 93
==23801== at 0x4026050: realloc (vg_replace_malloc.c:429)
==23801== by 0x54DC2EC: (within /usr/lib/libX11.so.6.2.0)
==23801== by 0x54DD98C: (within /usr/lib/libX11.so.6.2.0)
==23801== by 0x54DE591: (within /usr/lib/libX11.so.6.2.0)
==23801== by 0x54DF3FE: _XlcCreateLC (in /usr/lib/libX11.so.6.2.0)
==23801== by 0x550ACF0: _XlcUtf8Loader (in /usr/lib/libX11.so.6.2.0)
==23801== by 0x54E88E0: _XOpenLC (in /usr/lib/libX11.so.6.2.0)
==23801== by 0x54E8A9D: _XrmInitParseInfo (in /usr/lib/libX11.so.6.2.0)
==23801== by 0x54C8216: (within /usr/lib/libX11.so.6.2.0)
==23801== by 0x54CA2CB: XrmGetStringDatabase (in /usr/lib/libX11.so.6.2.0)
==23801== by 0x54A7D13: (within /usr/lib/libX11.so.6.2.0)
==23801== by 0x54A7E51: XGetDefault (in /usr/lib/libX11.so.6.2.0)
==23801==
==23801== LEAK SUMMARY:
==23801== definitely lost: 156 bytes in 2 blocks.
==23801== indirectly lost: 412 bytes in 15 blocks.
==23801== possibly lost: 0 bytes in 0 blocks.
==23801== still reachable: 135,493 bytes in 1,784 blocks.
==23801== suppressed: 0 bytes in 0 blocks.
==23801== Reachable blocks (those to which a pointer was found) are not shown.
==23801== To see them, rerun with: --leak-check=full --show-reachable=yes
If I run with --show-reachable=yes, I see in the output:
==23826== 12 bytes in 1 blocks are still reachable in loss record 5 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6D1D6C9: qt_plugin_instance (xview.cpp:259)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 6 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x700B973: qt_plugin_instance (xcf.cpp:2390)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 7 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6E2227F: qt_plugin_instance (tga.cpp:475)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 8 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6E182A7: qt_plugin_instance (rgb.cpp:644)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 9 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6E0DA7B: qt_plugin_instance (psd.cpp:362)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 10 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6E05895: qt_plugin_instance (pcx.cpp:640)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 11 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6D171CD: qt_plugin_instance (jp2.cpp:478)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 12 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x5E7DE33: qt_plugin_instance (exr.cpp:273)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 13 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6D06375: qt_plugin_instance (eps.cpp:356)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 14 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6CFD17B: qt_plugin_instance (dds.cpp:1076)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 15 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x6CF259D: qt_plugin_instance (main.cpp:93)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 16 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x5E77BD4: qt_plugin_instance (main.cpp:98)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 17 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x5E71468: qt_plugin_instance (main.cpp:94)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 18 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x5E65D5E: qt_plugin_instance (main.cpp:93)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 19 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x5E5C413: qt_plugin_instance (main.cpp:92)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
==23826==
==23826==
==23826== 12 bytes in 1 blocks are still reachable in loss record 20 of 93
==23826== at 0x402588D: operator new(unsigned int)
(vg_replace_malloc.c:224)
==23826== by 0x5E53D68: qt_plugin_instance (main.cpp:94)
==23826== by 0x4DD800D: QFactoryLoader::instance(QString const&) const
(qfactoryloader.cpp:237)
==23826== by 0x42975FB: QImageReader::supportedImageFormats()
(qimagereader.cpp:1404)
==23826== by 0x8048819: main (main.cpp:12)
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14 San Francisco, California: Nov 2 - 4
http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091001/5d48d96c/attachment.bin
More information about the Qt-interest-old
mailing list