wasm: Fix use after delete of QWasmSuspendResumeControl

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 <morten.sorvig@qt.io>
This commit is contained in:
Piotr Wiercinski 2025-03-31 15:47:09 +02:00
parent d139d22f7e
commit b8ff842ace
2 changed files with 5 additions and 3 deletions

View File

@ -89,13 +89,13 @@ EMSCRIPTEN_BINDINGS(qtQWasmIntegraton)
QWasmIntegration *QWasmIntegration::s_instance;
QWasmIntegration::QWasmIntegration()
: m_fontDb(nullptr)
: m_suspendResume(std::make_shared<QWasmSuspendResumeControl>()) // 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<QWasmSuspendResumeControl>()) // create early in order to register event handlers at startup
{
s_instance = this;

View File

@ -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<QWasmSuspendResumeControl> m_suspendResume;
mutable QWasmFontDatabase *m_fontDb;
mutable QWasmServices *m_desktopServices;
mutable QHash<QWindow *, QWasmBackingStore *> m_backingStores;
@ -107,7 +110,6 @@ private:
static QWasmIntegration *s_instance;
QWasmInputContext *m_wasmInputContext = nullptr;
std::shared_ptr<QWasmSuspendResumeControl> m_suspendResume;
#if QT_CONFIG(draganddrop)
std::unique_ptr<QWasmDrag> m_drag;