┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWendi Gan <[email protected]>2026-04-04 13:37:48 +0800
committerMéven Car <[email protected]>2026-04-26 09:42:34 +0000
commit2dce7352c1edfb13c90a8a3b858d113e3a9300b2 (patch)
treeca31668647df4addaa5e174dc13ea97f08e5ae1c /src
parente409f76a66b7fd8c11e6dd725d183c44837826de (diff)
Fix occasional UAF crashes in KConfig::sync() during exit
Previously, c035e95 introduced `QtConcurrent::run` to execute `KConfig::sync()` in a separate thread. However, this introduced thread-safety issue: BUG 518433 (UAF caused by RC): During application exit, the main thread frees the old `s_sessionConfig` in `KMWSessionManager::saveState()` to create a new one. Meanwhile, the worker thread is still iterating over the old instance's entryMap during `KConfig::sync()`, leading to a Use-After-Free (UAF) crash. Changes: Copy the `config` in the main thread so `KConfig::sync()` can safely run in the worker. BUG: 518433 BUG: 516481 CCBUG: 425627
Diffstat (limited to 'src')
-rw-r--r--src/dolphinmainwindow.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index e6da0f5e0..615e52480 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -87,6 +87,7 @@
#include <QLineEdit>
#include <QMenuBar>
#include <QPushButton>
+#include <QSharedPointer>
#include <QShowEvent>
#include <QStandardPaths>
#include <QTimer>
@@ -788,8 +789,10 @@ void DolphinMainWindow::slotSaveSession()
KConfigGroup group = config->group(QStringLiteral("Number"));
group.writeEntry("NumberOfWindows", 1); // Makes session restore aware that there is a window to restore.
- auto future = QtConcurrent::run([config]() {
- config->sync();
+ // Copy the config in the main thread so sync() can safely run in the worker.
+ QSharedPointer<KConfig> configCopy(config->copyTo(config->name()));
+ auto future = QtConcurrent::run([configCopy]() {
+ configCopy->sync();
});
m_sessionSaveWatcher->setFuture(future);
}