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) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-28 09:34:05 -06:00
1 parent 547d032995
commit 797957ea25
1 file changed
+4 -2
+4 -2
View File
@@ -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<std::mutex> 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<NativeInput> native = native_;
std::lock_guard<std::mutex> guard(native->mutex);
if (native->status != PSPOskNativeStatus::WAITING) {
native_ = std::make_shared<NativeInput>();
}
}