@@ -33,6 +33,12 @@ ModulesLoader::~ModulesLoader()
3333{
3434 quit ();
3535 wait ();
36+
37+ QMutexLocker locker (&m_mutex);
38+ for (auto &loader : m_pluginLoaders) {
39+ cleanupPluginLoader (loader);
40+ }
41+ m_pluginLoaders.clear ();
3642}
3743
3844ModulesLoader& ModulesLoader::instance ()
@@ -86,13 +92,15 @@ void ModulesLoader::findModule(const QString& path)
8692 // 版本过低则不加载,可能会导致登录器崩溃
8793 if (!checkVersion (version, LOWEST_VERSION)) {
8894 qCWarning (DDE_SHELL) << " The module version is too low, version:" << version << " , lowest version:" << LOWEST_VERSION;
95+ loader->deleteLater ();
8996 continue ;
9097 }
9198
9299 // 性能优化,分类加载
93100 QString pluginType = meta.value (" pluginType" ).toString ();
94101 if (!pluginType.isEmpty ()) {
95102 if ((pluginType == LoginType && !m_loadLoginModule) || (pluginType == TrayType && m_loadLoginModule)) {
103+ loader->deleteLater ();
96104 continue ;
97105 }
98106 } else {
@@ -103,27 +111,27 @@ void ModulesLoader::findModule(const QString& path)
103111 auto * moduleInstance = dynamic_cast <dss::module ::BaseModuleInterface*>(loader->instance ());
104112 if (!moduleInstance) {
105113 qCWarning (DDE_SHELL) << " Load plugin failed, error:" << loader->errorString ();
106- loader-> unload ( );
114+ cleanupPluginLoader (loader );
107115 continue ;
108116 }
109117
110118 qCInfo (DDE_SHELL) << " Current plugin key:" << moduleInstance->key ();
111119 if (blackList.contains (moduleInstance->key ())) {
112120 qCInfo (DDE_SHELL) << " The plugin is in black list, won't be loaded." ;
113- loader-> unload ( );
121+ cleanupPluginLoader (loader );
114122 continue ;
115123 }
116124
117125 int loadPluginType = moduleInstance->loadPluginType ();
118126 if (loadPluginType != dss::module ::BaseModuleInterface::Load) {
119127 qCInfo (DDE_SHELL) << " The plugin dose not want to be loaded." ;
120- loader-> unload ( );
128+ cleanupPluginLoader (loader );
121129 continue ;
122130 }
123131
124132 if (PluginManager::instance ()->contains (moduleInstance->key ())) {
125133 qCInfo (DDE_SHELL) << " The plugin has been loaded." ;
126- loader-> unload ( );
134+ cleanupPluginLoader (loader );
127135 continue ;
128136 }
129137
@@ -268,6 +276,7 @@ bool ModulesLoader::isPluginEnabled(const QFileInfo& module)
268276 auto dbusInterface = new QDBusInterface (service, targetPath, interface, dbusConnection);
269277 if (!dbusInterface || !dbusInterface->isValid ()) {
270278 qCWarning (DDE_SHELL) << " Check plugin enabled dbus interface is not valid." ;
279+ dbusInterface->deleteLater ();
271280 return false ;
272281 }
273282 const bool pluginEnabled = dbusInterface->property (property.toStdString ().c_str ()).toBool ();
@@ -346,6 +355,14 @@ void ModulesLoader::unloadPlugin(const QString& path)
346355 }
347356}
348357
358+ void ModulesLoader::cleanupPluginLoader (QPluginLoader* loader)
359+ {
360+ if (loader) {
361+ loader->unload ();
362+ loader->deleteLater ();
363+ }
364+ }
365+
349366// TODO 只重新加载/卸载变更的插件
350367void ModulesLoader::onDConfigPropertyChanged (const QString& key, const QVariant& value, QObject* objPtr)
351368{
@@ -367,4 +384,4 @@ void ModulesLoader::onDbusPropertiesChanged(const QString& interfaceName, const
367384 start (QThread::LowestPriority);
368385 }
369386 }
370- }
387+ }
0 commit comments