ExamplesListModel: Fix leak

Change-Id: I7243049cd9e9afa3b4790fda7967ce392c94527d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-01-22 16:52:27 +01:00
parent f05477dc39
commit e96feed16f

View File

@@ -46,6 +46,7 @@
#include <utils/stylehelper.h>
#include <algorithm>
#include <memory>
namespace QtSupport {
namespace Internal {
@@ -296,13 +297,13 @@ static bool isValidExampleOrDemo(ExampleItem *item)
void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
const QString &projectsOffset, const QString &examplesInstallPath)
{
ExampleItem *item = nullptr;
std::unique_ptr<ExampleItem> item;
const QChar slash = QLatin1Char('/');
while (!reader->atEnd()) {
switch (reader->readNext()) {
case QXmlStreamReader::StartElement:
if (reader->name() == QLatin1String("example")) {
item = new ExampleItem;
item = std::make_unique<ExampleItem>();
item->type = Example;
QXmlStreamAttributes attributes = reader->attributes();
item->name = attributes.value(QLatin1String("name")).toString();
@@ -335,8 +336,8 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
break;
case QXmlStreamReader::EndElement:
if (reader->name() == QLatin1String("example")) {
if (isValidExampleOrDemo(item))
m_items.append(item);
if (isValidExampleOrDemo(item.get()))
m_items.push_back(item.release());
} else if (reader->name() == QLatin1String("examples")) {
return;
}