From ef66779d0b927df73d63d027750e6b6907271a38 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 10 Jul 2024 09:40:55 -0700 Subject: [PATCH] gh-121460: Skip freeing unallocated arenas (gh-121491) `munmap(NULL)` is not noop, like `free(NULL)` is. Fixes an observed testsuite hang on 32-bit ARM systems. (cherry picked from commit a802277914405786f6425f2776605c44bd407fc0) Co-authored-by: Stefano Rivera --- Objects/obmalloc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 4fe195b63166c1..a9decc5dc1b1dd 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -386,8 +386,16 @@ _PyMem_ArenaFree(void *Py_UNUSED(ctx), void *ptr, ) { #ifdef MS_WINDOWS + /* Unlike free(), VirtualFree() does not special-case NULL to noop. */ + if (ptr == NULL) { + return; + } VirtualFree(ptr, 0, MEM_RELEASE); #elif defined(ARENAS_USE_MMAP) + /* Unlike free(), munmap() does not special-case NULL to noop. */ + if (ptr == NULL) { + return; + } munmap(ptr, size); #else free(ptr);