summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-07-21 07:59:47 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-07-21 07:59:47 +0000
commitc0c583d48b5d5204580d13ad1a4524af706b7c33 (patch)
treef175f8fa5ca8b963a027111db62268c3e8264398 /Python/pythonrun.c
parentae9f38f3316b5c68f8298ef00412f5ad92a072eb (diff)
downloadcpython-c0c583d48b5d5204580d13ad1a4524af706b7c33.tar.gz
Handle more memory allocation failures without crashing.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 95a337269b..bc832195ec 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, "<string>", start, flags,
- arena);
+ mod_ty mod;
+
+ if (arena == NULL)
+ return NULL;
+
+ mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
if (mod != NULL)
ret = run_mod(mod, "<string>", 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;