From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 10 Jul 2024 17:05:11 +0000 (+0200) Subject: [3.13] gh-121460: Skip freeing unallocated arenas (gh-121589) X-Git-Tag: v3.13.0b4~85 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=867cf402792bfc3b6db01c800cbce0e59fb3cfe1;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-121460: Skip freeing unallocated arenas (gh-121589) `munmap(NULL)` is not noop, like `free(NULL)` is. Fixes an observed testsuite hang on 32-bit ARM systems. (cherry picked from commit a802277914405786f6425f2776605c44bd407fc0, AKA gh-121491) Co-authored-by: Stefano Rivera --- diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 4fe195b63166..a9decc5dc1b1 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);