From 4c562f94c043d6b0594a61ffeae4368e05e29df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Tue, 5 Sep 2023 10:26:56 +0200 Subject: [PATCH] wasm: don't crash if app is deleteLater()ed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We check for a valid event dispatcher when waking up, but there was no check after processing queued events, and processEvents() would continue with a stale this pointer if one of the queued events happened to delete the application object. Fix this by checking if this is still a valid pointer after processing events. Fixes: QTBUG-116330 Change-Id: Ic4d91298986847e6095ce9daea51a4b974106c06 Reviewed-by: Piotr WierciƄski Reviewed-by: Lorn Potter (cherry picked from commit fefb1e18b1b6834ea344bed273735f096c61eb90) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 482e617ba18..dac02ad24dc 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -221,6 +221,11 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) QCoreApplication::sendPostedEvents(); processWindowSystemEvents(flags); + // The processPostedEvents() call above may process an event which deletes the + // application object and the event dispatcher; stop event processing in that case. + if (!isValidEventDispatcherPointer(this)) + return false; + if (m_interrupted) { m_interrupted = false; return false;