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>
This commit is contained in:
parent
0bc7f94bd8
commit
a93f07e977
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user