From 30691235c5acc4c5b30ffc8820d2ef7c55fc632e Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 7 Dec 2023 12:14:45 +0100 Subject: [PATCH] Do not cache indexes across async tasks Capturing an index is unsafe as it could be out of date when this is processed. The user could have changed directory inserted a file or changed sorting order. --- src/kitemviews/kfileitemmodelrolesupdater.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 06500b45dd..bcd172d026 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -1315,7 +1315,11 @@ void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &ite connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); auto listJob = KIO::listDir(url, KIO::HideProgressInfo); - QObject::connect(listJob, &KIO::ListJob::entries, this, [this, index](const KJob * /*job*/, const KIO::UDSEntryList &list) { + QObject::connect(listJob, &KIO::ListJob::entries, this, [this, item](const KJob * /*job*/, const KIO::UDSEntryList &list) { + int index = m_model->index(item); + if (index < 0) { + return; + } auto data = m_model->data(index); int origCount = data.value("count").toInt(); int entryCount = origCount;