From f07c27eec117c664e3c0101c3077524647a32662 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 21 Jul 2014 17:45:55 -0700 Subject: [PATCH] Don't store QLibraryPrivate with empty file names in the global store They shouldn't exist in the first place. They exist in two cases only: 1) mistake by the user in the QLibrary or QPluginLoader constructors or setFileName 2) as a kludge for setLoadHints before a file name is set (we need to store the user's requested hints somewhere) This is important for the second case, as otherwise all QLibrary and QPluginLoader objects without a file name would share the setting. Task-number: QTBUG-39642 Change-Id: Iebff0252fd4d95a1d54caf338d4e2fff4de3b189 Reviewed-by: David Faure --- src/corelib/plugin/qlibrary.cpp | 4 ++-- tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index ae53dcdc328..8af38acf511 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -455,7 +455,7 @@ inline QLibraryPrivate *QLibraryStore::findOrCreate(const QString &fileName, con lib = new QLibraryPrivate(fileName, version, loadHints); // track this library - if (Q_LIKELY(data)) + if (Q_LIKELY(data) && !fileName.isEmpty()) data->libraryMap.insert(fileName, lib); lib->libraryRefCount.ref(); @@ -475,7 +475,7 @@ inline void QLibraryStore::releaseLibrary(QLibraryPrivate *lib) // no one else is using Q_ASSERT(lib->libraryUnloadCount.load() == 0); - if (Q_LIKELY(data)) { + if (Q_LIKELY(data) && !lib->fileName.isEmpty()) { QLibraryPrivate *that = data->libraryMap.take(lib->fileName); Q_ASSERT(lib == that); Q_UNUSED(that); diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp index fc7e99103ca..2244f3e041c 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp +++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp @@ -456,6 +456,9 @@ void tst_QLibrary::loadHints() if (int(loadHints) != 0) { lh |= library.loadHints(); library.setLoadHints(lh); + + // confirm that another QLibrary doesn't get affected - QTBUG-39642 + QCOMPARE(QLibrary().loadHints(), QLibrary::LoadHints()); } library.setFileName(lib); QCOMPARE(library.loadHints(), lh);