From a93f07e9773257ac9385b6f7e3ca92df20318450 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 12 Jan 2022 19:13:46 +0200 Subject: tst_qeventdispatcher: fix UB in single-shot timers activation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Oswald Buddenhagen --- .../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/auto/corelib/kernel') 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); -- cgit v1.2.3