From 595078d856f454fb34c01d0ce85c12ebbf6e7788 Mon Sep 17 00:00:00 2001 From: hspir404 Date: Fri, 24 Jan 2025 03:25:08 -0800 Subject: [PATCH] Fix stale heap read in UnmapMemoryImpl --- src/core/memory.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index a8dd72acc..271092eaf 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -418,8 +418,9 @@ u64 MemoryManager::UnmapBytesFromEntry(VAddr virtual_addr, VirtualMemoryArea vma vma.phys_base = 0; vma.disallow_merge = false; vma.name = ""; - MergeAdjacent(vma_map, new_it); - bool readonly_file = vma.prot == MemoryProt::CpuRead && type == VMAType::File; + const auto post_merge_it = MergeAdjacent(vma_map, new_it); + auto& post_merge_vma = post_merge_it->second; + bool readonly_file = post_merge_vma.prot == MemoryProt::CpuRead && type == VMAType::File; if (type != VMAType::Reserved && type != VMAType::PoolReserved) { // Unmap the memory region. impl.Unmap(vma_base_addr, vma_base_size, start_in_vma, start_in_vma + adjusted_size,