From 2eb6d44c2c5e366e05946e3e36ec596bd73eed10 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 24 Sep 2024 20:08:07 +0200 Subject: [PATCH] prevent use after free through focusOutEvent when window is closed --- src/frontend/qt_sdl/Window.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 79b37e31a5..d40a062e85 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -780,6 +780,10 @@ void MainWindow::closeEvent(QCloseEvent* event) Config::Save(); emuInstance->deleteWindow(windowID, false); + + // emuInstance may be deleted + // prevent use after free from us + emuInstance = nullptr; QMainWindow::closeEvent(event); } @@ -970,7 +974,10 @@ void MainWindow::focusInEvent(QFocusEvent* event) void MainWindow::focusOutEvent(QFocusEvent* event) { - emuInstance->audioMute(); + // focusOutEvent is called through the window close event handler + // prevent use after free + if (emuInstance) + emuInstance->audioMute(); } void MainWindow::onAppStateChanged(Qt::ApplicationState state)