From: Victor Stinner Date: Fri, 9 Mar 2012 23:21:44 +0000 (+0100) Subject: Close #14232: catch mmap() failure in new_arena() of obmalloc X-Git-Tag: v3.3.0a2~247 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba108823b62a2eb3d5f6f067140ccebf6fee84bb;p=python Close #14232: catch mmap() failure in new_arena() of obmalloc --- diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 3d782a21cf..9cd6a50466 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -540,6 +540,8 @@ new_arena(void) { struct arena_object* arenaobj; uint excess; /* number of bytes above pool alignment */ + void *address; + int err; #ifdef PYMALLOC_DEBUG if (Py_GETENV("PYTHONMALLOCSTATS")) @@ -593,12 +595,14 @@ new_arena(void) unused_arena_objects = arenaobj->nextarena; assert(arenaobj->address == 0); #ifdef ARENAS_USE_MMAP - arenaobj->address = (uptr)mmap(NULL, ARENA_SIZE, PROT_READ|PROT_WRITE, + address = mmap(NULL, ARENA_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + err = (address == MAP_FAILED); #else - arenaobj->address = (uptr)malloc(ARENA_SIZE); + address = malloc(ARENA_SIZE); + err = (address == 0); #endif - if (arenaobj->address == 0) { + if (err) { /* The allocation failed: return NULL after putting the * arenaobj back. */ @@ -606,6 +610,7 @@ new_arena(void) unused_arena_objects = arenaobj; return NULL; } + arenaobj->address = (uptr)address; ++narenas_currently_allocated; #ifdef PYMALLOC_DEBUG