KFileItemModel: Delay emitting currentDirectoryRemoved() signal

The KCoreDirLister object is modified before KCoreDirListerCache::deleteDir()
returns because the signal currentDirectoryRemoved() is emitted.
This prevents removal of the deleted lister from dirData.listersCurrentlyHolding
in KCoreDirListerCache::forgetDirs() when the tab is closed, which causes the
crash described in the bug. Hence, the signal currentDirectoryRemoved()
is delayed to ensure this does not occur.

BUG: 473377
This commit is contained in:
Amol Godbole 2023-09-04 00:24:38 -05:00
parent d7535d6977
commit 9ba0904013

View file

@ -1197,7 +1197,12 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items)
for (const KFileItem &item : items) { for (const KFileItem &item : items) {
if (item.url() == currentDir) { if (item.url() == currentDir) {
Q_EMIT currentDirectoryRemoved(); // #473377: Delay emitting currentDirectoryRemoved() to avoid modifying KCoreDirLister
// before KCoreDirListerCache::deleteDir() returns.
QTimer::singleShot(0, this, [this] {
Q_EMIT currentDirectoryRemoved();
});
return; return;
} }