diff options
author | jian liang <jianliang79@gmail.com> | 2012-01-22 22:38:49 +0800 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-07 12:48:06 +0100 |
commit | e09025c1b6d43342e3086b7179109a08f39afd10 (patch) | |
tree | 9f5f4013390accdde391f11cda0c1b126ef0fe3b /src/corelib/plugin/qfactoryloader.cpp | |
parent | 3722bc5d3cd1b246f1480ea969a8d9cd5e41b1ee (diff) |
fix memory leak of QLibraryPrivate
this commit is aimed to fix QTBUG-4341. now QFactoryLoaderPrivate's
destructor will call unload() to QLibaryPrivate object which will destory
the plugin's root instance if its refcount reach zero.
Task-number: QTBUG-4341
Change-Id: I3cd3e071b34271bf5802ab09f6c125beda5e9844
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/plugin/qfactoryloader.cpp')
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index e887ae8bf9..fe5aea0e8a 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -78,8 +78,11 @@ public: QFactoryLoaderPrivate::~QFactoryLoaderPrivate() { - for (int i = 0; i < libraryList.count(); ++i) - libraryList.at(i)->release(); + for (int i = 0; i < libraryList.count(); ++i) { + QLibraryPrivate *library = libraryList.at(i); + library->unload(); + library->release(); + } } QFactoryLoader::QFactoryLoader(const char *iid, @@ -142,7 +145,10 @@ void QFactoryLoader::update() library->release(); continue; } - QObject *instance = library->instance(); + + if (!library->inst) + library->inst = library->instance(); + QObject *instance = library->inst.data(); if (!instance) { library->release(); // ignore plugins that have a valid signature but cannot be loaded. @@ -215,8 +221,11 @@ QObject *QFactoryLoader::instance(const QString &key) const QString lowered = d->cs ? key : key.toLower(); if (QLibraryPrivate* library = d->keyMap.value(lowered)) { if (library->instance || library->loadPlugin()) { - if (QObject *obj = library->instance()) { - if (obj && !obj->parent()) + if (!library->inst) + library->inst = library->instance(); + QObject *obj = library->inst.data(); + if (obj) { + if (!obj->parent()) obj->moveToThread(QCoreApplicationPrivate::mainThread()); return obj; } |