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>
This commit is contained in:
parent
a1b78213b3
commit
fb2ef1a66d
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user