]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-121460: Skip freeing unallocated arenas (gh-121589)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 10 Jul 2024 17:05:11 +0000 (19:05 +0200)
committerGitHub <noreply@github.com>
Wed, 10 Jul 2024 17:05:11 +0000 (17:05 +0000)
`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 <stefano@rivera.za.net>
Objects/obmalloc.c

index 4fe195b63166c17410d06415ad5deb1df77cb5d1..a9decc5dc1b1ddd955c92ef3e89ff338a196016a 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);