summaryrefslogtreecommitdiff
blob: 93a016d76fd016bb3c0e1c6f87ae340f8a7bc11a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From cd5040684723b87c7ba5b7cc1b1a63402902a641 Mon Sep 17 00:00:00 2001
From: Ada Christine <adachristine18@gmail.com>
Date: Sun, 27 Mar 2022 01:29:09 +0000
Subject: [PATCH] Fixed crash during KIdleTime::timeoutReached()

timeoutReached() will cause a crash if an item is removed from associations
during signal dispatch due to iterator invalidation. iterate over a
const container of the assoication keys only triggering ones matching
the current timeout value to avoid the crash and unnecessary copying

BUG: 451946
---
 src/kidletime.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/kidletime.cpp b/src/kidletime.cpp
index a58eaa6..0929285 100644
--- a/src/kidletime.cpp
+++ b/src/kidletime.cpp
@@ -288,13 +288,13 @@ void KIdleTimePrivate::timeoutReached(int msec)
 {
     Q_Q(KIdleTime);
 
-    for (auto it = associations.cbegin(); it != associations.cend(); ++it) {
-        if (it.value() == msec) {
+    const auto listKeys = associations.keys(msec);
+
+    for (const auto key : listKeys) {
 #if KIDLETIME_BUILD_DEPRECATED_SINCE(5, 76)
-            Q_EMIT q->timeoutReached(it.key());
+        Q_EMIT q->timeoutReached(key);
 #endif
-            Q_EMIT q->timeoutReached(it.key(), msec);
-        }
+        Q_EMIT q->timeoutReached(key, msec);
     }
 }
 
-- 
GitLab