FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Close #14232: catch mmap() failure in new_arena() of obmalloc · python/cpython@ba10882 · GitHub

Repository navigation

Commit ba10882

Browse files
committed
Close #14232: catch mmap() failure in new_arena() of obmalloc
1 parent 2839382 commit ba10882

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎Objects/obmalloc.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ new_arena(void)
540540
{
541541
struct arena_object* arenaobj;
542542
uint excess; /* number of bytes above pool alignment */
543+
void *address;
544+
int err;
543545

544546
#ifdef PYMALLOC_DEBUG
545547
if (Py_GETENV("PYTHONMALLOCSTATS"))
@@ -593,19 +595,22 @@ new_arena(void)
593595
unused_arena_objects = arenaobj->nextarena;
594596
assert(arenaobj->address == 0);
595597
#ifdef ARENAS_USE_MMAP
596-
arenaobj->address = (uptr)mmap(NULL, ARENA_SIZE, PROT_READ|PROT_WRITE,
598+
address = mmap(NULL, ARENA_SIZE, PROT_READ|PROT_WRITE,
597599
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
600+
err = (address == MAP_FAILED);
598601
#else
599-
arenaobj->address = (uptr)malloc(ARENA_SIZE);
602+
address = malloc(ARENA_SIZE);
603+
err = (address == 0);
600604
#endif
601-
if (arenaobj->address == 0) {
605+
if (err) {
602606
/* The allocation failed: return NULL after putting the
603607
* arenaobj back.
604608
*/
605609
arenaobj->nextarena = unused_arena_objects;
606610
unused_arena_objects = arenaobj;
607611
return NULL;
608612
}
613+
arenaobj->address = (uptr)address;
609614

610615
++narenas_currently_allocated;
611616
#ifdef PYMALLOC_DEBUG

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL