From c72d59a3f1260864fc2848c15f3b90e28c1f2da8 Mon Sep 17 00:00:00 2001 From: LC Date: Sat, 11 Jul 2026 16:50:53 -0400 Subject: [PATCH] 64BitAllocator: Avoid overwriting Region[0] in Create64BitAllocatorWithRegions Since this was a reference, this would end up overwriting Region[0] with whatever the smallest region was instead of just being a running pointer to what happened to be the current smallest region. We can switch over to a pointer to avoid obliterating the first memory region. --- FEXCore/Source/Utils/Allocator/64BitAllocator.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp b/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp index 6a207b3ee..596011030 100644 --- a/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp +++ b/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp @@ -623,14 +623,14 @@ fextl::unique_ptr make_alloc_unique(FEXCore::Allocator::MemoryRegion& Base, A fextl::unique_ptr Create64BitAllocatorWithRegions(fextl::vector& Regions) { // This is a bit tricky as we can't allocate memory safely except from the Regions provided. Otherwise we might overwrite memory pages we // don't own. Scan the memory regions and find the smallest one. - FEXCore::Allocator::MemoryRegion& Smallest = Regions[0]; - for (auto& it : Regions) { - if (it.Size <= Smallest.Size) { - Smallest = it; + FEXCore::Allocator::MemoryRegion* Smallest = &Regions[0]; + for (auto& Region : Regions) { + if (Region.Size <= Smallest->Size) { + Smallest = &Region; } } - return make_alloc_unique(Smallest, Regions); + return make_alloc_unique(*Smallest, Regions); } } // namespace Alloc::OSAllocator