summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2022-01-12 19:13:46 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2022-01-13 02:09:08 +0200
commita93f07e9773257ac9385b6f7e3ca92df20318450 (patch)
tree2e5c0b0700a11403207d7c6bea70dd40c221e4ff /tests/auto/corelib/kernel
parent0bc7f94bd8949b89b75c2730a743a2bbf74a0c01 (diff)
tst_qeventdispatcher: fix UB in single-shot timers activation
Any of these timers must be stopped before the corresponding test function completes. Otherwise, functors will operate on dangling pointers, which can lead to failures or unreliability of other tests. Fix this by setting a correct context in the QTimer::singleShot() call. Pick-to: 6.2 6.3 Change-Id: Icd23f6d9a2c6e7f33495d6badc4080a1b10c19f8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
index 21aee94e5d..9ef6c79bba 100644
--- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
+++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
@@ -371,7 +371,7 @@ void tst_QEventDispatcher::postedEventsPingPong()
// We should use Qt::CoarseTimer on Windows, to prevent event
// dispatcher from sending a posted event.
- QTimer::singleShot(500, Qt::CoarseTimer, [&mainLoop]() {
+ QTimer::singleShot(500, Qt::CoarseTimer, &mainLoop, [&mainLoop]() {
mainLoop.exit(1);
});
@@ -388,12 +388,12 @@ void tst_QEventDispatcher::eventLoopExit()
// Imitates QApplication::exec():
QEventLoop mainLoop;
// The test itself is a lambda:
- QTimer::singleShot(0, [&mainLoop]() {
+ QTimer::singleShot(0, &mainLoop, [&mainLoop]() {
// Two more single shots, both will be posted as events
// (zero timeout) and supposed to be processes by the
// mainLoop:
- QTimer::singleShot(0, [&mainLoop]() {
+ QTimer::singleShot(0, &mainLoop, [&mainLoop]() {
// wakeUp triggers QCocoaEventDispatcher into incrementing
// its 'serialNumber':
mainLoop.wakeUp();
@@ -402,7 +402,7 @@ void tst_QEventDispatcher::eventLoopExit()
QCoreApplication::processEvents();
});
- QTimer::singleShot(0, [&mainLoop]() {
+ QTimer::singleShot(0, &mainLoop, [&mainLoop]() {
// With QCocoaEventDispatcher this is executed while in the
// processEvents (see above) and would fail to actually
// interrupt the loop.
@@ -411,7 +411,7 @@ void tst_QEventDispatcher::eventLoopExit()
});
bool timeoutObserved = false;
- QTimer::singleShot(500, [&timeoutObserved, &mainLoop]() {
+ QTimer::singleShot(500, &mainLoop, [&timeoutObserved, &mainLoop]() {
// In case the QEventLoop::exit above failed, we have to bail out
// early, not wasting time:
mainLoop.exit();
@@ -434,7 +434,7 @@ void tst_QEventDispatcher::interruptTrampling()
auto dispatcher = eventDispatcher();
QVERIFY(dispatcher);
dispatcher->processEvents(QEventLoop::AllEvents);
- QTimer::singleShot(0, [dispatcher]() {
+ QTimer::singleShot(0, dispatcher, [dispatcher]() {
dispatcher->wakeUp();
});
dispatcher->processEvents(QEventLoop::WaitForMoreEvents);