From 9ba09040134f743ca3a2082589cc943c2d4bf175 Mon Sep 17 00:00:00 2001 From: Amol Godbole Date: Mon, 4 Sep 2023 00:24:38 -0500 Subject: [PATCH] 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 --- src/kitemviews/kfileitemmodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 40c76c7ef..f42f2c193 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -1197,7 +1197,12 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items) for (const KFileItem &item : items) { 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; } -- 2.47.3