Commit 7f83492a authored by Kevin Funk's avatar Kevin Funk

ASAN: Fix leak in KAStatsFavoritesModel

Summary:
Trace:
Direct leak of 336 byte(s) in 6 object(s) allocated from:
    #0 0x544cc0 in operator new(unsigned long) (/home/kfunk/devel/install/kf5/bin/plasmashell+0x544cc0)
    #1 0x7fbad15cddaf in KAStatsFavoritesModel::Private::entryForResource(QString const&) const /home/kfunk/devel/src/kf5/plasma-desktop/applets/kicker/plugin/kastatsfavoritesmodel.cpp:171:24
    #2 0x7fbad15b2d8e in KAStatsFavoritesModel::Private::addResult(QString const&, int, bool) /home/kfunk/devel/src/kf5/plasma-desktop/applets/kicker/plugin/kastatsfavoritesmodel.cpp:280:22
    #3 0x7fbad15b044f in KAStatsFavoritesModel::Private::Private(KAStatsFavoritesModel*, QString) /home/kfunk/devel/src/kf5/plasma-desktop/applets/kicker/plugin/kastatsfavoritesmodel.cpp:233:13
    #4 0x7fbad15a78ea in KAStatsFavoritesModel::initForClient(QString const&) /home/kfunk/devel/src/kf5/plasma-desktop/applets/kicker/plugin/kastatsfavoritesmodel.cpp:485:13
    ...

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D17039
parent 36bc000d
......@@ -76,8 +76,7 @@ public:
{
if (id.isEmpty()) return;
AbstractEntry *entry = nullptr;
QScopedPointer<AbstractEntry> deleter;
QSharedPointer<AbstractEntry> entry = nullptr;
if (parent->m_itemEntries.contains(id)) {
entry = parent->m_itemEntries[id];
......@@ -85,7 +84,6 @@ public:
// This entry is not cached - it is temporary,
// so let's clean up when we exit this function
entry = parent->entryForResource(id);
deleter.reset(entry);
}
if (!entry || !entry->isValid()) {
......@@ -105,7 +103,7 @@ public:
}
// If this is an application, use the applications:-format url
auto appEntry = dynamic_cast<AppEntry*>(entry);
auto appEntry = dynamic_cast<AppEntry*>(entry.data());
if (appEntry && !appEntry->menuId().isEmpty()) {
m_id = QStringLiteral("applications:") + appEntry->menuId();
return;
......@@ -149,30 +147,32 @@ public:
return NormalizedId(this, id);
}
AbstractEntry *entryForResource(const QString &resource) const
QSharedPointer<AbstractEntry> entryForResource(const QString &resource) const
{
using SP = QSharedPointer<AbstractEntry>;
const auto agent =
agentForUrl(resource);
if (agent == AGENT_CONTACTS) {
return new ContactEntry(q, resource);
return SP(new ContactEntry(q, resource));
} else if (agent == AGENT_DOCUMENTS) {
if (resource.startsWith(QLatin1String("/"))) {
return new FileEntry(q, QUrl::fromLocalFile(resource));
return SP(new FileEntry(q, QUrl::fromLocalFile(resource)));
} else {
return new FileEntry(q, QUrl(resource));
return SP(new FileEntry(q, QUrl(resource)));
}
} else if (agent == AGENT_APPLICATIONS) {
if (resource.startsWith(QLatin1String("applications:"))) {
return new AppEntry(q, resource.mid(13));
return SP(new AppEntry(q, resource.mid(13)));
} else {
return new AppEntry(q, resource);
return SP(new AppEntry(q, resource));
}
} else {
return nullptr;
return {};
}
}
......@@ -333,14 +333,13 @@ public:
m_items.removeAt(index);
// Removing the entry from the cache
QMutableHashIterator<QString, AbstractEntry*> i(m_itemEntries);
QMutableHashIterator<QString, QSharedPointer<AbstractEntry>> i(m_itemEntries);
while (i.hasNext()) {
i.next();
if (i.value() == entry) {
i.remove();
}
}
delete entry;
endRemoveRows();
}
......@@ -449,7 +448,7 @@ public:
QString m_clientId;
QVector<NormalizedId> m_items;
QHash<QString, AbstractEntry*> m_itemEntries;
QHash<QString, QSharedPointer<AbstractEntry>> m_itemEntries;
QStringList m_ignoredItems;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment