summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-02-21 13:58:57 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-27 07:09:18 +0100
commitcafb02911a29b98ac2652fde64e95870e70fd547 (patch)
tree4c9178b6f09e3a860abccc53b7ce696c056a4b6c /src/corelib/plugin
parent790fe22c52f15d4ba1c9e48d6f6847d286cb916f (diff)
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 <liang.qi@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r--src/corelib/plugin/qlibrary.cpp9
-rw-r--r--src/corelib/plugin/qlibrary_p.h2
2 files changed, 6 insertions, 5 deletions
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;