]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121460: Skip freeing unallocated arenas (gh-121491)
authorStefano Rivera <stefano@rivera.za.net>
Wed, 10 Jul 2024 16:40:55 +0000 (09:40 -0700)
committerGitHub <noreply@github.com>
Wed, 10 Jul 2024 16:40:55 +0000 (10:40 -0600)
`munmap(NULL)` is not noop, like `free(NULL)` is.

Fixes an observed testsuite hang on 32-bit ARM systems.

Objects/obmalloc.c

index d033e2bad1891a927158470f9e710097cc5f7c82..a6a71802ef8e0193505ba807d4986600fffe7f7a 100644 (file)
@@ -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);