summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2025-02-28 17:05:09 -0300
committerThiago Macieira <thiago.macieira@intel.com>2025-03-24 12:32:03 -0800
commitfb2ef1a66d487e6280f002a695ebb09f643eb526 (patch)
tree032b29ea6ed333b3c8c435f1d15791fea475057d /src/corelib/plugin
parenta1b78213b3d0d8cdda373fc710772ab8e93a836b (diff)
QFactoryLoader: do destroy the staticplugin instances too
The previous commit ensured we did delete the instances of regular, dynamic plugins when this QFactoryLoader went out of scope. This commit repeats the same technique for the staticplugins. Change-Id: Ic9ff94cf7a6de95c63fbfffd30b8a418c211e824 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r--src/corelib/plugin/qfactoryloader.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
index a7ce5994213..d0bb673e537 100644
--- a/src/corelib/plugin/qfactoryloader.cpp
+++ b/src/corelib/plugin/qfactoryloader.cpp
@@ -257,6 +257,7 @@ public:
QFactoryLoaderPrivate() { }
QByteArray iid;
mutable QMutex mutex;
+ mutable QList<QtPluginInstanceFunction> usedStaticInstances;
#if QT_CONFIG(library)
~QFactoryLoaderPrivate();
QDuplicateTracker<QString> loadedPaths;
@@ -438,6 +439,11 @@ QFactoryLoader::~QFactoryLoader()
}
}
#endif
+
+ for (QtPluginInstanceFunction staticInstance : d->usedStaticInstances) {
+ if (staticInstance)
+ delete staticInstance();
+ }
}
#if defined(Q_OS_UNIX) && !defined (Q_OS_DARWIN)
@@ -604,14 +610,19 @@ inline QObject *QFactoryLoader::instanceHelper_locked(int index) const
QLatin1StringView iid(d->iid.constData(), d->iid.size());
const QList<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
+ qsizetype i = 0;
for (QStaticPlugin plugin : staticPlugins) {
QByteArrayView pluginData(static_cast<const char *>(plugin.rawMetaData), plugin.rawMetaDataSize);
if (!isIidMatch(pluginData, iid))
continue;
- if (index == 0)
+ if (i == index) {
+ if (d->usedStaticInstances.size() <= i)
+ d->usedStaticInstances.resize(i + 1);
+ d->usedStaticInstances[i] = plugin.instance;
return plugin.instance();
- --index;
+ }
+ ++i;
}
return nullptr;