From 797957ea254e27a14fe83b3d183ebb5bf47c6412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 25 Sep 2026 18:17:11 -0600 Subject: [PATCH] OSK: Fix a use-after-free when loading a savestate DoState replaced native_ while holding a lock_guard on its mutex, so the old NativeInput could be freed before the guard unlocked it. Crashed every state load (e.g. Splinter Cell Essentials, anywhere in the game). Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/Dialog/PSPOskDialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Core/Dialog/PSPOskDialog.cpp b/Core/Dialog/PSPOskDialog.cpp index 8e0ab56a30..f19bd41faf 100755 --- a/Core/Dialog/PSPOskDialog.cpp +++ b/Core/Dialog/PSPOskDialog.cpp @@ -1099,8 +1099,10 @@ void PSPOskDialog::DoState(PointerWrap &p) if (p.mode == p.MODE_READ) { // A box still open can answer into the loaded state (the next Update would only open // another). One that finished before mustn't block the next. - std::lock_guard guard(native_->mutex); - if (native_->status != PSPOskNativeStatus::WAITING) { + // Hold a reference, so the guard doesn't outlive the mutex it unlocks when native_ is replaced. + std::shared_ptr native = native_; + std::lock_guard guard(native->mutex); + if (native->status != PSPOskNativeStatus::WAITING) { native_ = std::make_shared(); } }