From 7a239ff62f35eb749751c707de11cb0588775ce3 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 27 Jan 2020 13:18:42 +0100 Subject: [PATCH] ExamplesListModel: Fix leaks Amends e96feed16fd75cbe16af1dbdc9e064cab740ffcc. Change-Id: I9782fbc7f2ce0698efc0011e26653eb280ee23d4 Reviewed-by: Christian Kandeler --- src/plugins/qtsupport/exampleslistmodel.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp index 5e0fbded258..c82dae0f170 100644 --- a/src/plugins/qtsupport/exampleslistmodel.cpp +++ b/src/plugins/qtsupport/exampleslistmodel.cpp @@ -351,13 +351,13 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader, void ExamplesListModel::parseDemos(QXmlStreamReader *reader, const QString &projectsOffset, const QString &demosInstallPath) { - ExampleItem *item = nullptr; + std::unique_ptr item; const QChar slash = QLatin1Char('/'); while (!reader->atEnd()) { switch (reader->readNext()) { case QXmlStreamReader::StartElement: if (reader->name() == QLatin1String("demo")) { - item = new ExampleItem; + item = std::make_unique(); item->type = Demo; QXmlStreamAttributes attributes = reader->attributes(); item->name = attributes.value(QLatin1String("name")).toString(); @@ -381,8 +381,8 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader, break; case QXmlStreamReader::EndElement: if (reader->name() == QLatin1String("demo")) { - if (isValidExampleOrDemo(item)) - m_items.append(item); + if (isValidExampleOrDemo(item.get())) + m_items.push_back(item.release()); } else if (reader->name() == QLatin1String("demos")) { return; } @@ -395,13 +395,13 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader, void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset) { - ExampleItem *item = nullptr; + std::unique_ptr item; const QChar slash = QLatin1Char('/'); while (!reader->atEnd()) { switch (reader->readNext()) { case QXmlStreamReader::StartElement: if (reader->name() == QLatin1String("tutorial")) { - item = new ExampleItem; + item = std::make_unique(); item->type = Tutorial; QXmlStreamAttributes attributes = reader->attributes(); item->name = attributes.value(QLatin1String("name")).toString(); @@ -428,7 +428,7 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString & break; case QXmlStreamReader::EndElement: if (reader->name() == QLatin1String("tutorial")) - m_items.append(item); + m_items.push_back(item.release()); else if (reader->name() == QLatin1String("tutorials")) return; break;