From e96feed16fd75cbe16af1dbdc9e064cab740ffcc Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 22 Jan 2020 16:52:27 +0100 Subject: [PATCH] ExamplesListModel: Fix leak Change-Id: I7243049cd9e9afa3b4790fda7967ce392c94527d Reviewed-by: Christian Stenger --- src/plugins/qtsupport/exampleslistmodel.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp index 64f9511b245..5e0fbded258 100644 --- a/src/plugins/qtsupport/exampleslistmodel.cpp +++ b/src/plugins/qtsupport/exampleslistmodel.cpp @@ -46,6 +46,7 @@ #include #include +#include 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 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(); 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; }