From 50c9a919424f6efcfc8bc47a973324997d0db568 Mon Sep 17 00:00:00 2001 From: rcaridade145 Date: Fri, 28 Nov 2025 18:54:45 +0000 Subject: [PATCH] rsx: Free previous pointer after reallocating memory After realloc in simple_array free the memory referenced by the old pointer. --- rpcs3/Emu/RSX/Common/simple_array.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpcs3/Emu/RSX/Common/simple_array.hpp b/rpcs3/Emu/RSX/Common/simple_array.hpp index 69397291f9..dda8cb5b3a 100644 --- a/rpcs3/Emu/RSX/Common/simple_array.hpp +++ b/rpcs3/Emu/RSX/Common/simple_array.hpp @@ -24,11 +24,18 @@ namespace rsx template void* realloc(void* prev_ptr, [[maybe_unused]] size_t prev_size, size_t new_size) { + ensure(reinterpret_cast(prev_ptr) % Align == 0, + "Pointer not aligned to Align"); + if (prev_size >= ((new_size + Align - 1) & (0 - Align))) + { + return prev_ptr; + } #ifdef _WIN32 return _aligned_realloc(prev_ptr, new_size, Align); #else void* ret = std::aligned_alloc(Align, new_size); std::memcpy(ret, prev_ptr, std::min(prev_size, new_size)); + std::free(prev_ptr); return ret; #endif }