From: Fushan Wen Date: Mon, 19 May 2025 11:56:15 +0000 (+0800) Subject: [PATCH] components/sessionprivate: fix a potential crash in SessionsModel X-Git-Tag: archive/raspbian/4%6.3.5-1+rpi1^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3e748956deb0337f3f0f409776a4e1ef712eb900;p=plasma-workspace.git [PATCH] components/sessionprivate: fix a potential crash in SessionsModel The problem is that std::function is passed by reference instead of copy, which might become dangling in the finished slot. (cherry picked from commit 3ed6ee211bbad1f5d76afa1f30844bebad17bed4) Co-authored-by: Fushan Wen (cherry picked from commit 995b597b24ca96aaea81f71781de8ddf60adf5e1) Co-authored-by: Fushan Wen Gbp-Pq: Name upstream_72719edd_components-sessionprivate-fix-a-potential-crash-in-SessionsModel.patch --- diff --git a/components/sessionsprivate/sessionsmodel.cpp b/components/sessionsprivate/sessionsmodel.cpp index b3f66f4d..20bda2b6 100644 --- a/components/sessionsprivate/sessionsmodel.cpp +++ b/components/sessionsprivate/sessionsmodel.cpp @@ -187,11 +187,11 @@ void SessionsModel::reload() } } -void SessionsModel::checkScreenLocked(const std::function &cb) +void SessionsModel::checkScreenLocked(std::function &&cb) { auto reply = m_screensaverInterface->GetActive(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [cb](QDBusPendingCallWatcher *watcher) { + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [cb = std::move(cb)](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (!reply.isError()) { cb(reply.value()); diff --git a/components/sessionsprivate/sessionsmodel.h b/components/sessionsprivate/sessionsmodel.h index 81084748..bc580d74 100644 --- a/components/sessionsprivate/sessionsmodel.h +++ b/components/sessionsprivate/sessionsmodel.h @@ -91,7 +91,7 @@ Q_SIGNALS: void aboutToLockScreen(); private: - void checkScreenLocked(const std::function &cb); + void checkScreenLocked(std::function &&cb); KDisplayManager m_displayManager;