From d12bd012a6a4729b5a77c1019ca9da4e9d1b7e3e Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Fri, 21 Jul 2006 07:59:47 +0000 Subject: Handle more memory allocation failures without crashing. --- Python/pythonrun.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 95a337269b7..bc832195ecb 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1204,8 +1204,12 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, { PyObject *ret = NULL; PyArena *arena = PyArena_New(); - mod_ty mod = PyParser_ASTFromString(str, "", start, flags, - arena); + mod_ty mod; + + if (arena == NULL) + return NULL; + + mod = PyParser_ASTFromString(str, "", start, flags, arena); if (mod != NULL) ret = run_mod(mod, "", globals, locals, flags, arena); PyArena_Free(arena); @@ -1218,8 +1222,13 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, { PyObject *ret; PyArena *arena = PyArena_New(); - mod_ty mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, - flags, NULL, arena); + mod_ty mod; + + if (arena == NULL) + return NULL; + + mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, + flags, NULL, arena); if (mod == NULL) { PyArena_Free(arena); return NULL; -- cgit v1.3.1