From 68dc052432150e9eecb46df039bf3cc95546ef26 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin <stenzek@gmail.com> Date: Sat, 26 Dec 2020 16:49:43 +1000 Subject: [PATCH] Bus: Don't leak shared memory when starting->stopping->starting --- src/core/bus.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/bus.cpp b/src/core/bus.cpp index ca6a6a0ee..4bb8948f2 100644 --- a/src/core/bus.cpp +++ b/src/core/bus.cpp @@ -106,6 +106,7 @@ static std::tuple<TickCount, TickCount, TickCount> CalculateMemoryTiming(MEMDELA static void RecalculateMemoryTimings(); static bool AllocateMemory(); +static void ReleaseMemory(); static void SetCodePageFastmemProtection(u32 page_index, bool writable); @@ -149,11 +150,7 @@ void Shutdown() CPU::g_state.fastmem_base = nullptr; m_fastmem_mode = CPUFastmemMode::Disabled; - if (g_ram) - { - m_memory_arena.ReleaseViewPtr(g_ram, RAM_SIZE); - g_ram = nullptr; - } + ReleaseMemory(); } void Reset() @@ -276,9 +273,21 @@ bool AllocateMemory() return false; } + Log_InfoPrintf("RAM is %u bytes at %p", RAM_SIZE, g_ram); return true; } +void ReleaseMemory() +{ + if (g_ram) + { + m_memory_arena.ReleaseViewPtr(g_ram, RAM_SIZE); + g_ram = nullptr; + } + + m_memory_arena.Destroy(); +} + static ALWAYS_INLINE u32 FastmemAddressToLUTPageIndex(u32 address) { return address >> 12;