From 95685b820757938fd712d3105baa106138d8c62a Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Wed, 12 Jan 2022 23:01:05 +0000 Subject: [PATCH] Avoid iterator invalidation segfault when unregistering a syncpt waiter erase invalidated `it` leading to a potential segfault if the GPU was very far behind, bail out early to avoid that since there can only be one occurence at most in the buffer anyway. --- app/src/main/cpp/skyline/soc/host1x/syncpoint.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/soc/host1x/syncpoint.cpp b/app/src/main/cpp/skyline/soc/host1x/syncpoint.cpp index 9995c118..b1d79536 100644 --- a/app/src/main/cpp/skyline/soc/host1x/syncpoint.cpp +++ b/app/src/main/cpp/skyline/soc/host1x/syncpoint.cpp @@ -29,9 +29,12 @@ namespace skyline::soc::host1x { // We want to ensure the iterator still exists prior to erasing it // Otherwise, if an invalid iterator was passed in then it could lead to UB // It is important to avoid UB in that case since the deregister isn't called from a locked context - for (auto it{waiters.begin()}; it != waiters.end(); it++) - if (it == waiter) + for (auto it{waiters.begin()}; it != waiters.end(); it++) { + if (it == waiter) { waiters.erase(it); + return; + } + } } u32 Syncpoint::Increment() {