From: Stefano Rivera Date: Wed, 10 Jul 2024 16:40:55 +0000 (-0700) Subject: gh-121460: Skip freeing unallocated arenas (gh-121491) X-Git-Tag: v3.14.0a1~1176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a802277914405786f6425f2776605c44bd407fc0;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index d033e2bad189..a6a71802ef8e 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);