Skip to content

Commit

Permalink
prevent use after free through focusOutEvent when window is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
RSDuck committed Sep 24, 2024
1 parent 2179ca2 commit 2eb6d44
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/frontend/qt_sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2eb6d44

Please sign in to comment.