summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtimerinfo_unix.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-03-22 11:19:53 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-03-26 13:04:48 +0100
commit1bdc74ad7b9d3c7d203a8cd6970474872798c2d6 (patch)
tree2a722186064905b2a34c6f4ee7d03011e57f99ce /src/corelib/kernel/qtimerinfo_unix.cpp
parent27ebeeb50e192ead7f839cbfcf13a2a42132a920 (diff)
Document a peculiarity that might plausibly confuse readers
It at first sight seems perverse to null-check a variable we've repeatedly dereferenced before, without visibly setting it since; however, its address was stored where an event handler could get at it, to clear it if deleting the object it points to. The check against null really is needed, but the reason is non-obvious; so document the reason and save the next developers to come this way some confusion. In the process, relocate a related comment that belonged one line earlier. Change-Id: Id67b86edc5a9a76a827d66b5c0abcd017d98a2bb Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/kernel/qtimerinfo_unix.cpp')
-rw-r--r--src/corelib/kernel/qtimerinfo_unix.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp
index bcaaf7af05..db4d4b1188 100644
--- a/src/corelib/kernel/qtimerinfo_unix.cpp
+++ b/src/corelib/kernel/qtimerinfo_unix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -631,13 +631,16 @@ int QTimerInfoList::activateTimers()
if (currentTimerInfo->interval > 0)
n_act++;
+ // Send event, but don't allow it to recurse:
if (!currentTimerInfo->activateRef) {
- // send event, but don't allow it to recurse
currentTimerInfo->activateRef = &currentTimerInfo;
QTimerEvent e(currentTimerInfo->id);
QCoreApplication::sendEvent(currentTimerInfo->obj, &e);
+ // Storing currentTimerInfo's address in its activateRef allows the
+ // handling of that event to clear this local variable on deletion
+ // of the object it points to - if it didn't, clear activateRef:
if (currentTimerInfo)
currentTimerInfo->activateRef = nullptr;
}