diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2025-02-28 17:05:09 -0300 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2025-03-24 12:32:03 -0800 |
| commit | fb2ef1a66d487e6280f002a695ebb09f643eb526 (patch) | |
| tree | 032b29ea6ed333b3c8c435f1d15791fea475057d /src | |
| parent | a1b78213b3d0d8cdda373fc710772ab8e93a836b (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')
| -rw-r--r-- | src/corelib/kernel/qpermissions_darwin.mm | 8 | ||||
| -rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 15 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/corelib/kernel/qpermissions_darwin.mm b/src/corelib/kernel/qpermissions_darwin.mm index ed45899543a..9753fc38845 100644 --- a/src/corelib/kernel/qpermissions_darwin.mm +++ b/src/corelib/kernel/qpermissions_darwin.mm @@ -38,14 +38,6 @@ QPermissionPlugin *permissionPlugin(const QPermission &permission) auto className = metaDataList.at(i).value(QtPluginMetaDataKeys::ClassName).toString(); qCDebug(lcPermissions) << "Found matching plugin" << qUtf8Printable(className); auto *plugin = static_cast<QPermissionPlugin*>(pluginLoader()->instance(i)); - if (!plugin->parent()) { - // Also, as setParent will involve sending a ChildAdded event to the parent, - // we need to make the call on the same thread as the parent lives, as events - // are not allowed to be sent to an object owned by another thread. - QMetaObject::invokeMethod(plugin, [=] { - plugin->setParent(pluginLoader); - }); - } return plugin; } } 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; |
