Skip to content

Commit 540ea21

Browse files
committed
check the right return value for mmap (dotnet#77952)
1 parent 16495db commit 540ea21

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
641641
size_t alignedSize = size + (alignment - OS_PAGE_SIZE);
642642
void * pRetVal = mmap(nullptr, alignedSize, PROT_NONE, MAP_ANON | MAP_PRIVATE | hugePagesFlag, -1, 0);
643643

644-
if (pRetVal != NULL)
644+
if (pRetVal != MAP_FAILED)
645645
{
646646
void * pAlignedRetVal = (void *)(((size_t)pRetVal + (alignment - 1)) & ~(alignment - 1));
647647
size_t startPadding = (size_t)pAlignedRetVal - (size_t)pRetVal;
@@ -663,9 +663,10 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
663663
// Do not include reserved memory in coredump.
664664
madvise(pRetVal, size, MADV_DONTDUMP);
665665
#endif
666+
return pRetVal;
666667
}
667668

668-
return pRetVal;
669+
return NULL; // return NULL if mmap failed
669670
}
670671

671672
// Reserve virtual memory range.

0 commit comments

Comments
 (0)