[frameworks/kio] src/widgets: KDirModel: ignore stale listing completion for a directory no longer in the model

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 182fc462ab396b823137a82eee36e2ef483a7ae1 by Méven Car.
Committed on 24/07/2026 at 09:04.
Pushed by meven into branch 'master'.

KDirModel: ignore stale listing completion for a directory no longer in the model

_k_slotCompleted() looked up the node for the completed directory and passed it
straight to isDir(), which dereferences the node. When openUrl() switches to
another URL before an earlier listing finishes, the old directory's node is
already gone and nodeForUrl() returns nullptr, so isDir(nullptr) crashed with a
SEGV (seen in KDirModelTest::testShowRoot under ASan).

Return early when the node is not found, mirroring the guard in _k_slotNewItems().

M  +5    -0    src/widgets/kdirmodel.cpp

https://invent.kde.org/frameworks/kio/-/commit/182fc462ab396b823137a82eee36e2ef483a7ae1

diff --git a/src/widgets/kdirmodel.cpp b/src/widgets/kdirmodel.cpp
index fdca37059a..b489284e6c 100644
--- a/src/widgets/kdirmodel.cpp
+++ b/src/widgets/kdirmodel.cpp
@@ -620,6 +620,11 @@ void KDirModelPrivate::_k_slotNewItems(const QUrl &directoryUrl, const KFileItem
 void KDirModelPrivate::_k_slotCompleted(const QUrl &directoryUrl)
 {
     KDirModelNode *result = nodeForUrl(directoryUrl); // O(depth)
+    if (!result) {
+        // Directory no longer in the model (openUrl() switched away before this
+        // listing finished). Ignore the stale completion.
+        return;
+    }
     Q_ASSERT(isDir(result));
     KDirModelDirNode *dirNode = static_cast<KDirModelDirNode *>(result);
     m_urlsBeingFetched.remove(dirNode);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.