summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 2dbcf75ac9..555c39d533 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -17,7 +17,9 @@
#include "eval.h"
#include "marshal.h"
+#ifdef HAVE_SIGNAL_H
#include <signal.h>
+#endif
#ifdef HAVE_LANGINFO_H
#include <locale.h>
@@ -738,6 +740,11 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
ps2 = PyString_AsString(w);
}
arena = PyArena_New();
+ if (arena == NULL) {
+ Py_XDECREF(v);
+ Py_XDECREF(w);
+ return -1;
+ }
mod = PyParser_ASTFromFile(fp, filename,
Py_single_input, ps1, ps2,
flags, &errcode, arena);
@@ -1056,6 +1063,17 @@ PyErr_PrintEx(int set_sys_last_vars)
}
PyErr_Fetch(&exception2, &v2, &tb2);
PyErr_NormalizeException(&exception2, &v2, &tb2);
+ /* It should not be possible for exception2 or v2
+ to be NULL. However PyErr_Display() can't
+ tolerate NULLs, so just be safe. */
+ if (exception2 == NULL) {
+ exception2 = Py_None;
+ Py_INCREF(exception2);
+ }
+ if (v2 == NULL) {
+ v2 = Py_None;
+ Py_INCREF(v2);
+ }
if (Py_FlushLine())
PyErr_Clear();
fflush(stdout);
@@ -1063,8 +1081,8 @@ PyErr_PrintEx(int set_sys_last_vars)
PyErr_Display(exception2, v2, tb2);
PySys_WriteStderr("\nOriginal exception was:\n");
PyErr_Display(exception, v, tb);
- Py_XDECREF(exception2);
- Py_XDECREF(v2);
+ Py_DECREF(exception2);
+ Py_DECREF(v2);
Py_XDECREF(tb2);
}
Py_XDECREF(result);
@@ -1184,9 +1202,12 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
PyObject *locals, PyCompilerFlags *flags)
{
PyObject *ret = NULL;
+ mod_ty mod;
PyArena *arena = PyArena_New();
- mod_ty mod = PyParser_ASTFromString(str, "<string>", start, flags,
- arena);
+ 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);
@@ -1198,9 +1219,13 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
PyObject *ret;
+ mod_ty mod;
PyArena *arena = PyArena_New();
- mod_ty mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
- flags, NULL, arena);
+ if (arena == NULL)
+ return NULL;
+
+ mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
+ flags, NULL, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
@@ -1263,8 +1288,12 @@ Py_CompileStringFlags(const char *str, const char *filename, int start,
PyCompilerFlags *flags)
{
PyCodeObject *co;
+ mod_ty mod;
PyArena *arena = PyArena_New();
- mod_ty mod = PyParser_ASTFromString(str, filename, start, flags, arena);
+ if (arena == NULL)
+ return NULL;
+
+ mod = PyParser_ASTFromString(str, filename, start, flags, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
@@ -1283,8 +1312,12 @@ struct symtable *
Py_SymtableString(const char *str, const char *filename, int start)
{
struct symtable *st;
+ mod_ty mod;
PyArena *arena = PyArena_New();
- mod_ty mod = PyParser_ASTFromString(str, filename, start, NULL, arena);
+ if (arena == NULL)
+ return NULL;
+
+ mod = PyParser_ASTFromString(str, filename, start, NULL, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;