From 8a79637e1454c751c24a984b7fb8af4c4d43394b Mon Sep 17 00:00:00 2001 From: Bubu <54771283+CeSun@users.noreply.github.com> Date: Sun, 16 Feb 2025 14:36:28 +0800 Subject: [PATCH] Fixed the issue of incorrect return value of PalVirtualAlloc (#112579) * Fixed the issue that the PalVirtualAlloc function did not return a NULL value correctly when memory allocation failed on Unix-like platforms * Fix variable name spelling --- src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp index 42b1c29db41f54..24172b9c3707e5 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp @@ -834,8 +834,10 @@ REDHAWK_PALEXPORT _Ret_maybenull_ _Post_writable_byte_size_(size) void* REDHAWK_ flags |= MAP_JIT; } #endif - - return mmap(NULL, size, unixProtect, flags, -1, 0); + void* pMappedMemory = mmap(NULL, size, unixProtect, flags, -1, 0); + if (pMappedMemory == MAP_FAILED) + return NULL; + return pMappedMemory; } REDHAWK_PALEXPORT void REDHAWK_PALAPI PalVirtualFree(_In_ void* pAddress, size_t size)