Skip to content

Commit a802277

Browse files
authored
gh-121460: Skip freeing unallocated arenas (gh-121491)
`munmap(NULL)` is not noop, like `free(NULL)` is. Fixes an observed testsuite hang on 32-bit ARM systems.
1 parent 0177a34 commit a802277

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)