[PATCH] components/sessionprivate: fix a potential crash in SessionsModel
authorFushan Wen <qydwhotmail@gmail.com>
Mon, 19 May 2025 11:56:15 +0000 (19:56 +0800)
committerAurélien COUDERC <coucouf@debian.org>
Tue, 20 May 2025 06:31:26 +0000 (08:31 +0200)
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 <qydwhotmail@gmail.com>
(cherry picked from commit 995b597b24ca96aaea81f71781de8ddf60adf5e1)

Co-authored-by: Fushan Wen <qydwhotmail@gmail.com>
Gbp-Pq: Name upstream_72719edd_components-sessionprivate-fix-a-potential-crash-in-SessionsModel.patch

components/sessionsprivate/sessionsmodel.cpp
components/sessionsprivate/sessionsmodel.h

index b3f66f4d2c30c6245adc2a38e19f54aff5c6fe81..20bda2b6c124144e9ee66e41a415e00592215d85 100644 (file)
@@ -187,11 +187,11 @@ void SessionsModel::reload()
     }
 }
 
-void SessionsModel::checkScreenLocked(const std::function<void(bool)> &cb)
+void SessionsModel::checkScreenLocked(std::function<void(bool)> &&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<bool> reply = *watcher;
         if (!reply.isError()) {
             cb(reply.value());
index 81084748b16c8da880395592e0da7e8cfe737a44..bc580d7406d3aa62e0e843e04f5b0610dca9f437 100644 (file)
@@ -91,7 +91,7 @@ Q_SIGNALS:
     void aboutToLockScreen();
 
 private:
-    void checkScreenLocked(const std::function<void(bool)> &cb);
+    void checkScreenLocked(std::function<void(bool)> &&cb);
 
     KDisplayManager m_displayManager;