Commit a8a8b79c authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fix use after free

CID:248855
parent a1c2b2b5
......@@ -106,17 +106,19 @@ void KisTemplateTree::writeTemplateTree()
}
}
void KisTemplateTree::add(KisTemplateGroup *g)
bool KisTemplateTree::add(KisTemplateGroup *g)
{
KisTemplateGroup *group = find(g->name());
if (group == 0)
if (group == 0) {
m_groups.append(g);
else {
group->addDir(g->dirs().first()); // "...there can be only one..." (Queen)
delete g;
g = 0;
return true;
}
group->addDir(g->dirs().first()); // "...there can be only one..." (Queen)
delete g;
g = 0;
return false;
}
KisTemplateGroup *KisTemplateTree::find(const QString &name) const
......@@ -160,9 +162,11 @@ void KisTemplateTree::readGroups()
sortingWeight = dg.readEntry("X-KDE-SortingWeight", 1000);
}
KisTemplateGroup *g = new KisTemplateGroup(name, templateDir.absolutePath() + QDir::separator(), sortingWeight);
add(g);
if (defaultTab == "true")
m_defaultGroup = g;
if (add(g)) {
if (defaultTab == "true") {
m_defaultGroup = g;
}
}
}
}
}
......
......@@ -42,7 +42,7 @@ public:
void readTemplateTree();
void writeTemplateTree();
void add(KisTemplateGroup *g);
bool add(KisTemplateGroup *g);
KisTemplateGroup *find(const QString &name) const;
KisTemplateGroup *defaultGroup() const {
......
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