forked from qt-creator/qt-creator
ExamplesListModel: Fix leaks
Amends e96feed16f
.
Change-Id: I9782fbc7f2ce0698efc0011e26653eb280ee23d4
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -351,13 +351,13 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
|
|||||||
void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
|
void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
|
||||||
const QString &projectsOffset, const QString &demosInstallPath)
|
const QString &projectsOffset, const QString &demosInstallPath)
|
||||||
{
|
{
|
||||||
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("demo")) {
|
if (reader->name() == QLatin1String("demo")) {
|
||||||
item = new ExampleItem;
|
item = std::make_unique<ExampleItem>();
|
||||||
item->type = Demo;
|
item->type = Demo;
|
||||||
QXmlStreamAttributes attributes = reader->attributes();
|
QXmlStreamAttributes attributes = reader->attributes();
|
||||||
item->name = attributes.value(QLatin1String("name")).toString();
|
item->name = attributes.value(QLatin1String("name")).toString();
|
||||||
@@ -381,8 +381,8 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
|
|||||||
break;
|
break;
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
if (reader->name() == QLatin1String("demo")) {
|
if (reader->name() == QLatin1String("demo")) {
|
||||||
if (isValidExampleOrDemo(item))
|
if (isValidExampleOrDemo(item.get()))
|
||||||
m_items.append(item);
|
m_items.push_back(item.release());
|
||||||
} else if (reader->name() == QLatin1String("demos")) {
|
} else if (reader->name() == QLatin1String("demos")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -395,13 +395,13 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
|
|||||||
|
|
||||||
void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset)
|
void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset)
|
||||||
{
|
{
|
||||||
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("tutorial")) {
|
if (reader->name() == QLatin1String("tutorial")) {
|
||||||
item = new ExampleItem;
|
item = std::make_unique<ExampleItem>();
|
||||||
item->type = Tutorial;
|
item->type = Tutorial;
|
||||||
QXmlStreamAttributes attributes = reader->attributes();
|
QXmlStreamAttributes attributes = reader->attributes();
|
||||||
item->name = attributes.value(QLatin1String("name")).toString();
|
item->name = attributes.value(QLatin1String("name")).toString();
|
||||||
@@ -428,7 +428,7 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &
|
|||||||
break;
|
break;
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
if (reader->name() == QLatin1String("tutorial"))
|
if (reader->name() == QLatin1String("tutorial"))
|
||||||
m_items.append(item);
|
m_items.push_back(item.release());
|
||||||
else if (reader->name() == QLatin1String("tutorials"))
|
else if (reader->name() == QLatin1String("tutorials"))
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user