From f79cc2d66b16af40aef7af1803c3ba50c939b03f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 5 Feb 2013 13:39:54 -0800 Subject: Fix crash-on-exit with some plugin systems (e.g. sensors) Don't assume that all entries in the QLibrary global data refer to libraries have have been loaded. There are three (not two) ways of getting entries there: 1) creating a QLibrary 2) using the static QLibrary::resolve 3) via plugins The unload code was meant to handle the first two cases only: libraries are still loaded at the end of the execution if the static methods were called or if QLibrary objects were leaked. It didn't handle the case of plugins being found by the directory scanner in QFactoryLoader but never loaded. Note it's possible that this assertion also happened with leaked QLibrary. Change-Id: Idcd7a551f96d8fe500cbca682f8014f5122b7584 Reviewed-by: Thomas McGuire Reviewed-by: Lars Knoll --- src/corelib/plugin/qlibrary.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 40b6b0d150..236832097a 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -373,17 +373,18 @@ inline void QLibraryStore::cleanup() for (; it != data->libraryMap.end(); ++it) { QLibraryPrivate *lib = it.value(); if (lib->libraryRefCount.load() == 1) { - Q_ASSERT(lib->pHnd); - Q_ASSERT(lib->libraryUnloadCount.load() > 0); - lib->libraryUnloadCount.store(1); + if (lib->libraryUnloadCount.load() > 0) { + Q_ASSERT(lib->pHnd); + lib->libraryUnloadCount.store(1); #ifdef __GLIBC__ - // glibc has a bug in unloading from global destructors - // see https://bugzilla.novell.com/show_bug.cgi?id=622977 - // and http://sourceware.org/bugzilla/show_bug.cgi?id=11941 - lib->unload(QLibraryPrivate::NoUnloadSys); + // glibc has a bug in unloading from global destructors + // see https://bugzilla.novell.com/show_bug.cgi?id=622977 + // and http://sourceware.org/bugzilla/show_bug.cgi?id=11941 + lib->unload(QLibraryPrivate::NoUnloadSys); #else - lib->unload(); + lib->unload(); #endif + } delete lib; it.value() = 0; } -- cgit v1.2.3