[Python-checkins] cpython: Close #14232: catch mmap() failure in new_arena() of obmalloc
victor.stinner
python-checkins at python.org
Sat Mar 10 00:21:41 CET 2012
http://hg.python.org/cpython/rev/ba8f85e16dd9
changeset: 75511:ba8f85e16dd9
user: Victor Stinner <victor.stinner at gmail.com>
date: Sat Mar 10 00:21:44 2012 +0100
summary:
Close #14232: catch mmap() failure in new_arena() of obmalloc
files:
Objects/obmalloc.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -540,6 +540,8 @@
{
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 @@
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 @@
unused_arena_objects = arenaobj;
return NULL;
}
+ arenaobj->address = (uptr)address;
++narenas_currently_allocated;
#ifdef PYMALLOC_DEBUG
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list