From 9155cd7491a7746da00e459ade023c217daaff61 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 4 Dec 2021 14:51:02 -0800 Subject: [PATCH] Debugger: Reduce meminfo block check hazard. If a debugger (i.e. the memory view) checks for memory block info while a save state is being loaded, it can crash. This was already rare, but this change makes it significantly rarer. Of course, it's still possible without a mutex, but I'm wanting to avoid slowing down the lookups as they are used at runtime within emulation. --- Core/Debugger/MemBlockInfo.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index 5750c6735f..13837df6bd 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -162,7 +162,9 @@ void MemSlabMap::DoState(PointerWrap &p) { int count = 0; if (p.mode == p.MODE_READ) { - Clear(); + // Since heads_ is a static size, let's avoid clearing it. + // This helps in case a debugger call happens concurrently. + Slab *old = first_; Do(p, count); first_ = new Slab(); @@ -170,7 +172,6 @@ void MemSlabMap::DoState(PointerWrap &p) { lastFind_ = first_; --count; - heads_.resize(SLICES, nullptr); FillHeads(first_); Slab *slab = first_; @@ -183,6 +184,13 @@ void MemSlabMap::DoState(PointerWrap &p) { FillHeads(slab); } + + // Now that it's entirely disconnected, delete the old slabs. + while (old != nullptr) { + Slab *next = old->next; + delete old; + old = next; + } } else { for (Slab *slab = first_; slab != nullptr; slab = slab->next) ++count;