diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-11-07 08:41:28 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-11-07 08:41:28 (GMT) |
commit | b271b3e18820eaaf8f6a7a41f462451d98a0ad2c (patch) | |
tree | b196d40272ce896432ffac441fe774e3ff72fdb9 /Python/pythonrun.c | |
parent | 6cad3712b316a9b3436e6ee455909f655404d236 (diff) | |
download | cpython-b271b3e18820eaaf8f6a7a41f462451d98a0ad2c.zip cpython-b271b3e18820eaaf8f6a7a41f462451d98a0ad2c.tar.gz cpython-b271b3e18820eaaf8f6a7a41f462451d98a0ad2c.tar.bz2 |
Issue #15001: fix segfault on "del sys.modules['__main__']"
Patch by Victor Stinner.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index afb4c51..a2e1e74 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -907,19 +907,20 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, { PyObject *m, *d, *v; const char *ext; - int set_file_name = 0, ret, len; + int set_file_name = 0, len, ret = -1; m = PyImport_AddModule("__main__"); if (m == NULL) return -1; + Py_INCREF(m); d = PyModule_GetDict(m); if (PyDict_GetItemString(d, "__file__") == NULL) { PyObject *f = PyString_FromString(filename); if (f == NULL) - return -1; + goto done; if (PyDict_SetItemString(d, "__file__", f) < 0) { Py_DECREF(f); - return -1; + goto done; } set_file_name = 1; Py_DECREF(f); @@ -932,7 +933,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, fclose(fp); if ((fp = fopen(filename, "rb")) == NULL) { fprintf(stderr, "python: Can't reopen .pyc file\n"); - ret = -1; goto done; } /* Turn on optimization if a .pyo file is given */ @@ -945,7 +945,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, } if (v == NULL) { PyErr_Print(); - ret = -1; goto done; } Py_DECREF(v); @@ -955,6 +954,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, done: if (set_file_name && PyDict_DelItemString(d, "__file__")) PyErr_Clear(); + Py_DECREF(m); return ret; } |