forked from qt-creator/qt-creator
ExamplesListModel: Fix leak
Change-Id: I7243049cd9e9afa3b4790fda7967ce392c94527d Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -296,13 +297,13 @@ static bool isValidExampleOrDemo(ExampleItem *item)
|
|||||||
void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
|
void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
|
||||||
const QString &projectsOffset, const QString &examplesInstallPath)
|
const QString &projectsOffset, const QString &examplesInstallPath)
|
||||||
{
|
{
|
||||||
ExampleItem *item = nullptr;
|
std::unique_ptr<ExampleItem> item;
|
||||||
const QChar slash = QLatin1Char('/');
|
const QChar slash = QLatin1Char('/');
|
||||||
while (!reader->atEnd()) {
|
while (!reader->atEnd()) {
|
||||||
switch (reader->readNext()) {
|
switch (reader->readNext()) {
|
||||||
case QXmlStreamReader::StartElement:
|
case QXmlStreamReader::StartElement:
|
||||||
if (reader->name() == QLatin1String("example")) {
|
if (reader->name() == QLatin1String("example")) {
|
||||||
item = new ExampleItem;
|
item = std::make_unique<ExampleItem>();
|
||||||
item->type = Example;
|
item->type = Example;
|
||||||
QXmlStreamAttributes attributes = reader->attributes();
|
QXmlStreamAttributes attributes = reader->attributes();
|
||||||
item->name = attributes.value(QLatin1String("name")).toString();
|
item->name = attributes.value(QLatin1String("name")).toString();
|
||||||
@@ -335,8 +336,8 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
|
|||||||
break;
|
break;
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
if (reader->name() == QLatin1String("example")) {
|
if (reader->name() == QLatin1String("example")) {
|
||||||
if (isValidExampleOrDemo(item))
|
if (isValidExampleOrDemo(item.get()))
|
||||||
m_items.append(item);
|
m_items.push_back(item.release());
|
||||||
} else if (reader->name() == QLatin1String("examples")) {
|
} else if (reader->name() == QLatin1String("examples")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user