prevent use after free through focusOutEvent when window is closed

This commit is contained in:
RSDuck 2024-09-24 20:08:07 +02:00
parent 2179ca2a41
commit 2eb6d44c2c
1 changed files with 8 additions and 1 deletions

View File

@ -780,6 +780,10 @@ void MainWindow::closeEvent(QCloseEvent* event)
Config::Save(); Config::Save();
emuInstance->deleteWindow(windowID, false); emuInstance->deleteWindow(windowID, false);
// emuInstance may be deleted
// prevent use after free from us
emuInstance = nullptr;
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
@ -970,6 +974,9 @@ void MainWindow::focusInEvent(QFocusEvent* event)
void MainWindow::focusOutEvent(QFocusEvent* event) void MainWindow::focusOutEvent(QFocusEvent* event)
{ {
// focusOutEvent is called through the window close event handler
// prevent use after free
if (emuInstance)
emuInstance->audioMute(); emuInstance->audioMute();
} }