diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-11-07 08:07:22 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-11-07 08:07:22 (GMT) |
commit | 33363f43e34defa17ad958ad6d718328f9e78db8 (patch) | |
tree | af52bccb1704c7a4eb3549436ea8ac1848c63b68 /Python | |
parent | c3fb3c3fa0688327d31715cb374c6825158f9d75 (diff) | |
parent | 5c6b3e214ce3506c454e8009602f0de651cc7922 (diff) | |
download | cpython-33363f43e34defa17ad958ad6d718328f9e78db8.zip cpython-33363f43e34defa17ad958ad6d718328f9e78db8.tar.gz cpython-33363f43e34defa17ad958ad6d718328f9e78db8.tar.bz2 |
Issue #15001: fix segfault on "del sys.module['__main__']"
Patch by Victor Stinner.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 7c4fb4a..dd32017 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1390,25 +1390,26 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, { PyObject *m, *d, *v; const char *ext; - int set_file_name = 0, ret; + int set_file_name = 0, ret = -1; size_t len; m = PyImport_AddModule("__main__"); if (m == NULL) return -1; + Py_INCREF(m); d = PyModule_GetDict(m); if (PyDict_GetItemString(d, "__file__") == NULL) { PyObject *f; f = PyUnicode_DecodeFSDefault(filename); if (f == NULL) - return -1; + goto done; if (PyDict_SetItemString(d, "__file__", f) < 0) { Py_DECREF(f); - return -1; + goto done; } if (PyDict_SetItemString(d, "__cached__", Py_None) < 0) { Py_DECREF(f); - return -1; + goto done; } set_file_name = 1; Py_DECREF(f); @@ -1422,7 +1423,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, fclose(fp); if ((pyc_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 */ @@ -1451,7 +1451,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, flush_io(); if (v == NULL) { PyErr_Print(); - ret = -1; goto done; } Py_DECREF(v); @@ -1459,6 +1458,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; } |