From 022a29fe580be39646b9ea7fb9bcb4f5fe0255ec Mon Sep 17 00:00:00 2001 From: Adrian <78108584+AdrianCassar@users.noreply.github.com> Date: Sat, 21 Mar 2026 12:22:49 +0000 Subject: [PATCH] [XAM] Fixed potential use-after-free on profile login --- src/xenia/kernel/xam/profile_manager.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/xenia/kernel/xam/profile_manager.cc b/src/xenia/kernel/xam/profile_manager.cc index 1d3a10d33..33bb26479 100644 --- a/src/xenia/kernel/xam/profile_manager.cc +++ b/src/xenia/kernel/xam/profile_manager.cc @@ -278,10 +278,11 @@ void ProfileManager::Login(const uint64_t xuid, const uint8_t user_index, } // Find if xuid is already logged in. We might want to logout. - for (auto& logged_profile : logged_profiles_) { - if (logged_profile.second->xuid() == xuid) { - Logout(logged_profile.first); - } + auto it = std::find_if( + logged_profiles_.begin(), logged_profiles_.end(), + [xuid](const auto& entry) { return entry.second->xuid() == xuid; }); + if (it != logged_profiles_.end()) { + Logout(it->first); } if (!accounts_.count(xuid)) {