From b8ff842ace2b4bd9f7dc6a10e71e6545bd66a138 Mon Sep 17 00:00:00 2001 From: Piotr Wiercinski Date: Mon, 31 Mar 2025 15:47:09 +0200 Subject: [PATCH] wasm: Fix use after delete of QWasmSuspendResumeControl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m_inputContext and other fields depends on the lifetime of m_suspendResume, but the latter gets destroyed first. Make sure that m_suspendResume is initialized first. Fixes: QTBUG-135378 Change-Id: Ifa2d58ec06a1f832549478bece3a8f651276ac8f Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmintegration.cpp | 4 ++-- src/plugins/platforms/wasm/qwasmintegration.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 2798b06f2bd..e3cdf11fa27 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -89,13 +89,13 @@ EMSCRIPTEN_BINDINGS(qtQWasmIntegraton) QWasmIntegration *QWasmIntegration::s_instance; QWasmIntegration::QWasmIntegration() - : m_fontDb(nullptr) + : m_suspendResume(std::make_shared()) // create early in order to register event handlers at startup + , m_fontDb(nullptr) , m_desktopServices(nullptr) , m_clipboard(new QWasmClipboard) #if QT_CONFIG(accessibility) , m_accessibility(new QWasmAccessibility) #endif - , m_suspendResume(std::make_shared()) // create early in order to register event handlers at startup { s_instance = this; diff --git a/src/plugins/platforms/wasm/qwasmintegration.h b/src/plugins/platforms/wasm/qwasmintegration.h index 50bed742c70..045f00de4dc 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.h +++ b/src/plugins/platforms/wasm/qwasmintegration.h @@ -95,6 +95,9 @@ private: QWasmScreen *wasmScreen; }; + // m_suspendResume should be created first and destroyed early as other fields depend on it + std::shared_ptr m_suspendResume; + mutable QWasmFontDatabase *m_fontDb; mutable QWasmServices *m_desktopServices; mutable QHash m_backingStores; @@ -107,7 +110,6 @@ private: static QWasmIntegration *s_instance; QWasmInputContext *m_wasmInputContext = nullptr; - std::shared_ptr m_suspendResume; #if QT_CONFIG(draganddrop) std::unique_ptr m_drag;