Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 78990:4754c4a710e6
Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when filename points to a pyc/pyo file and closeit is false.
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Tue, 11 Sep 2012 14:11:03 +0200 |
| parents | 92c6bbf7bb85 |
| children | c3539eb02470 |
line wrap: on
line diff
--- a/Python/pythonrun.c Tue Sep 11 14:08:49 2012 +0200 +++ b/Python/pythonrun.c Tue Sep 11 14:11:03 2012 +0200 @@ -1385,7 +1385,7 @@ { PyObject *m, *d, *v; const char *ext; - int set_file_name = 0, ret; + int set_file_name = 0, close_own_fp = 0, ret; size_t len; m = PyImport_AddModule("__main__"); @@ -1419,6 +1419,7 @@ ret = -1; goto done; } + close_own_fp = 1; /* Turn on optimization if a .pyo file is given */ if (strcmp(ext, ".pyo") == 0) Py_OptimizeFlag = 1; @@ -1449,6 +1450,9 @@ Py_DECREF(v); ret = 0; done: + if (close_own_fp) { + fclose(fp); + } if (set_file_name && PyDict_DelItemString(d, "__file__")) PyErr_Clear(); return ret;
