diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-06-24 03:41:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-24 03:41:40 (GMT) |
commit | 8f8ad2c38237caf5ee48f690289e8c811d245455 (patch) | |
tree | c8f8fbd15d8d0be1ce397ab4322f84295bf85d43 /Python/pythonrun.c | |
parent | 7729d6d27d5d31b9764dec4a96a458015be3ecb8 (diff) | |
download | cpython-8f8ad2c38237caf5ee48f690289e8c811d245455.zip cpython-8f8ad2c38237caf5ee48f690289e8c811d245455.tar.gz cpython-8f8ad2c38237caf5ee48f690289e8c811d245455.tar.bz2 |
bpo-33451: Close pyc files before calling PyEval_EvalCode() (GH-7884)
Directly executed pyc files were being kept open longer than necessary.
(cherry picked from commit ea737751b10fff752aafed0231e8a02b82ba365d)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index e644e2a..b23cfda 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -408,7 +408,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, goto done; } v = run_pyc_file(pyc_fp, filename, d, d, flags); - fclose(pyc_fp); } else { /* When running from stdin, leave __main__.__loader__ alone */ if (strcmp(filename, "<stdin>") != 0 && @@ -1041,27 +1040,31 @@ run_pyc_file(FILE *fp, const char *filename, PyObject *globals, if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError, "Bad magic number in .pyc file"); - return NULL; + goto error; } /* Skip mtime and size */ (void) PyMarshal_ReadLongFromFile(fp); (void) PyMarshal_ReadLongFromFile(fp); - if (PyErr_Occurred()) - return NULL; - + if (PyErr_Occurred()) { + goto error; + } v = PyMarshal_ReadLastObjectFromFile(fp); if (v == NULL || !PyCode_Check(v)) { Py_XDECREF(v); PyErr_SetString(PyExc_RuntimeError, "Bad code object in .pyc file"); - return NULL; + goto error; } + fclose(fp); co = (PyCodeObject *)v; v = PyEval_EvalCode((PyObject*)co, globals, locals); if (v && flags) flags->cf_flags |= (co->co_flags & PyCF_MASK); Py_DECREF(co); return v; +error: + fclose(fp); + return NULL; } PyObject * |