From cafb02911a29b98ac2652fde64e95870e70fd547 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 21 Feb 2013 13:58:57 -0800 Subject: Make sure that the reference count for plugins is kept correctly For systems where the Unix signature checker isn't enabled (read: Mac and Windows), QPluginLoader must actually load the plugin to query for the metadata. On Mac it even tried to keep the library loaded to avoid unloading and reloading again when the user calls load(). However, that plus the fact that it was calling load_sys() (on Mac) meant that it would bypass the reference count checking. And on all Unix, if a library-that-wasnt-a-plugin was already loaded by way of a QLibrary, it would have an effect of unloading said library. So remove the "caching" of the library. We should instead invest time to write a proper Mach-O binary decoder. Task-number: QTBUG-29776 Change-Id: Iebbddabe60047aafedeced21f26a170f59656757 Reviewed-by: Liang Qi Reviewed-by: Shawn Rutledge --- src/corelib/plugin/qlibrary.cpp | 9 ++++----- src/corelib/plugin/qlibrary_p.h | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 1e17c9fbd4..3432f9619d 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -711,7 +711,7 @@ void QLibraryPrivate::updatePluginState() hTempModule = ::LoadLibraryEx((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, dwFlags); SetErrorMode(oldmode); #else - temporary_load = load_sys(); + temporary_load = load(); #endif } QtPluginQueryVerificationDataFunction getMetaData = NULL; @@ -736,11 +736,10 @@ void QLibraryPrivate::updatePluginState() if (getMetaData) ret = qt_get_metadata(getMetaData, this, &exceptionThrown); + if (temporary_load) + unload(); if (!exceptionThrown) { - if (!ret) { - if (temporary_load) - unload_sys(); - } else { + if (ret) { success = true; } retryLoadLibrary = false; diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index b425e0d590..abf11be9f7 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -127,7 +127,9 @@ private: bool unload_sys(); QFunctionPointer resolve_sys(const char *); + /// counts how many QLibrary or QPluginLoader are attached to us, plus 1 if it's loaded QAtomicInt libraryRefCount; + /// counts how many times load() or loadPlugin() were called QAtomicInt libraryUnloadCount; enum { IsAPlugin, IsNotAPlugin, MightBeAPlugin } pluginState; -- cgit v1.2.3