diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-08-03 21:54:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-03 21:54:06 (GMT) |
commit | d8078626770a8d358eb83d7928c12d75ff4e821a (patch) | |
tree | ad7ad443185ae8daa4e7d08a96a4acbe79050455 /Modules/main.c | |
parent | 46dc4e34ed8005a688d7f3512844ef227a3465f4 (diff) | |
download | cpython-d8078626770a8d358eb83d7928c12d75ff4e821a.zip cpython-d8078626770a8d358eb83d7928c12d75ff4e821a.tar.gz cpython-d8078626770a8d358eb83d7928c12d75ff4e821a.tar.bz2 |
bpo-34170: Fix pymain_run_file() (GH-8660)
bpo-34170, bpo-34326: Fix pymain_run_file(): use
PyRun_AnyFileExFlags(closeit=1) instead of calling fclose(fp)
explicitly to close the input file before running the code.
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Modules/main.c b/Modules/main.c index 06aa112..da3441f 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -1129,14 +1129,16 @@ pymain_run_file(_PyMain *pymain, _PyCoreConfig *config, PyCompilerFlags *cf) "%ls: '%ls' is a directory, cannot continue\n", config->program, filename); pymain->status = 1; - goto done; + fclose(fp); + return; } /* call pending calls like signal handlers (SIGINT) */ if (Py_MakePendingCalls() == -1) { PyErr_Print(); pymain->status = 1; - goto done; + fclose(fp); + return; } PyObject *unicode, *bytes = NULL; @@ -1155,12 +1157,10 @@ pymain_run_file(_PyMain *pymain, _PyCoreConfig *config, PyCompilerFlags *cf) filename_str = "<filename encoding error>"; } - int run = PyRun_AnyFileExFlags(fp, filename_str, 0, cf); + /* PyRun_AnyFileExFlags(closeit=1) calls fclose(fp) before running code */ + int run = PyRun_AnyFileExFlags(fp, filename_str, 1, cf); Py_XDECREF(bytes); pymain->status = (run != 0); - -done: - fclose(fp); } |