forked from openkylin/ukui-search
修复搜索插件生命周期管理内存泄漏问题
This commit is contained in:
parent
f5eaf99f6f
commit
df3332046f
|
@ -37,11 +37,6 @@ PluginManager *PluginManager::getInstance()
|
|||
return global_instance;
|
||||
}
|
||||
|
||||
void PluginManager::setPluginEnableByName(const QString &pluginName, bool enable)
|
||||
{
|
||||
m_hash.value(pluginName)->setEnable(enable);
|
||||
}
|
||||
|
||||
PluginManager::PluginManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QDir pluginsDir(PLUGIN_INSTALL_DIRS);
|
||||
|
@ -73,12 +68,11 @@ PluginManager::PluginManager(QObject *parent) : QObject(parent)
|
|||
PluginInterface *piface = dynamic_cast<PluginInterface*>(plugin);
|
||||
if (!piface)
|
||||
continue;
|
||||
m_hash.insert(piface->name(), piface);
|
||||
switch (piface->pluginType()) {
|
||||
case PluginInterface::PluginType::SearchPlugin: {
|
||||
auto p = dynamic_cast<SearchPluginIface *>(plugin);
|
||||
if (!SearchPluginManager::getInstance()->registerExternalPlugin(p, pluginsDir.absoluteFilePath(fileName))) {
|
||||
m_hash.erase(m_hash.find(piface->name()));
|
||||
if(!SearchPluginManager::getInstance()->registerExternalPlugin(p, pluginsDir.absoluteFilePath(fileName))) {
|
||||
delete p;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -96,6 +90,4 @@ PluginManager::PluginManager(QObject *parent) : QObject(parent)
|
|||
|
||||
PluginManager::~PluginManager()
|
||||
{
|
||||
m_hash.clear();
|
||||
SearchPluginManager::getInstance()->close();
|
||||
}
|
||||
|
|
|
@ -41,16 +41,11 @@ public:
|
|||
Q_SIGNALS:
|
||||
void pluginStateChanged(const QString &pluginName, bool enable);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setPluginEnableByName(const QString &pluginName, bool enable);
|
||||
|
||||
private:
|
||||
explicit PluginManager(QObject *parent = nullptr);
|
||||
|
||||
~PluginManager();
|
||||
|
||||
QHash<QString, PluginInterface*> m_hash;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,10 @@ bool SearchPluginManager::registerPlugin(UkuiSearch::SearchPluginIface *plugin)
|
|||
|
||||
if (m_map.end() != m_map.find(plugin->name())) {
|
||||
qWarning() << "the plugin:" << plugin->name() << "has been registered.";
|
||||
if (plugin) {
|
||||
delete plugin;
|
||||
plugin = nullptr;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -440,11 +444,6 @@ SearchPluginIface *SearchPluginManager::getPlugin(const QString &pluginId)
|
|||
return m_map[pluginId];
|
||||
}
|
||||
|
||||
void SearchPluginManager::close()
|
||||
{
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
SearchPluginManager::~SearchPluginManager()
|
||||
{
|
||||
for (auto iter = m_map.begin(); iter != m_map.end();) {
|
||||
|
|
|
@ -56,8 +56,6 @@ public:
|
|||
const QList<PluginInfo> getPluginIds();
|
||||
SearchPluginIface *getPlugin(const QString &pluginId);
|
||||
|
||||
void close();
|
||||
|
||||
private:
|
||||
explicit SearchPluginManager(QObject *parent = nullptr);
|
||||
~SearchPluginManager();
|
||||
|
|
Loading…
Reference in New Issue