Skip to content

Commit

Permalink
xdgdesktopportal: properly fix a dangling pointer
Browse files Browse the repository at this point in the history
The previous fix didn't actually work, as it kept a reference
into a container which could have been muted by the time the
reference was going to be used.

Use an index instead.

Amends 32c09ea.

Change-Id: Ib855b4a663c281467e46536b98a0ce2b961f19ee
Pick-to: 5.15
Task-number: QTBUG-87143
Reviewed-by: Michael Weghorn <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
dangelog committed Oct 6, 2020
1 parent 227fa93 commit 45a0c68
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void QXdgDesktopPortalFileDialog::openPortal()
qDBusRegisterMetaType<FilterList>();

FilterList filterList;
Filter* selectedFilter = nullptr;
auto selectedFilterIndex = filterList.size() - 1;

d->userVisibleToNameFilter.clear();

Expand All @@ -236,7 +236,7 @@ void QXdgDesktopPortalFileDialog::openPortal()
filterList << filter;

if (!d->selectedMimeTypeFilter.isEmpty() && d->selectedMimeTypeFilter == mimeTypefilter)
selectedFilter = &filterList.last();
selectedFilterIndex = filterList.size() - 1;
}
} else if (!d->nameFilters.isEmpty()) {
for (const QString &nameFilter : d->nameFilters) {
Expand Down Expand Up @@ -265,17 +265,16 @@ void QXdgDesktopPortalFileDialog::openPortal()
d->userVisibleToNameFilter.insert(userVisibleName, nameFilter);

if (!d->selectedNameFilter.isEmpty() && d->selectedNameFilter == nameFilter)
selectedFilter = &filterList.last();
selectedFilterIndex = filterList.size() - 1;
}
}
}

if (!filterList.isEmpty())
options.insert(QLatin1String("filters"), QVariant::fromValue(filterList));

if (selectedFilter) {
options.insert(QLatin1String("current_filter"), QVariant::fromValue(*selectedFilter));
}
if (selectedFilterIndex != -1)
options.insert(QLatin1String("current_filter"), QVariant::fromValue(filterList[selectedFilterIndex]));

options.insert(QLatin1String("handle_token"), QStringLiteral("qt%1").arg(QRandomGenerator::global()->generate()));

Expand Down

0 comments on commit 45a0c68

Please sign in to comment.