[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 a802277914, AKA gh-121491)

Co-authored-by: Stefano Rivera <stefano@rivera.za.net>
This commit is contained in:
Miss Islington (bot) 2024-07-10 19:05:11 +02:00 committed by GitHub
parent 0113c56a20
commit 867cf40279
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View 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);