Skip to content

Commit 867cf40

Browse files
[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 a802277, AKA gh-121491) Co-authored-by: Stefano Rivera <[email protected]>
1 parent 0113c56 commit 867cf40

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Objects/obmalloc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,16 @@ _PyMem_ArenaFree(void *Py_UNUSED(ctx), void *ptr,
386386
)
387387
{
388388
#ifdef MS_WINDOWS
389+
/* Unlike free(), VirtualFree() does not special-case NULL to noop. */
390+
if (ptr == NULL) {
391+
return;
392+
}
389393
VirtualFree(ptr, 0, MEM_RELEASE);
390394
#elif defined(ARENAS_USE_MMAP)
395+
/* Unlike free(), munmap() does not special-case NULL to noop. */
396+
if (ptr == NULL) {
397+
return;
398+
}
391399
munmap(ptr, size);
392400
#else
393401
free(ptr);

0 commit comments

Comments
 (0)