summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2012-09-11 12:11:03 (GMT)
committerChristian Heimes <christian@cheimes.de>2012-09-11 12:11:03 (GMT)
commiteeb5635843810ee67f2b18b96f4266d134d913ee (patch)
treea384134435cea140997b598712dda5214f008712 /Python/pythonrun.c
parent05823f7d6783440920b11024bfc76f15e86093af (diff)
downloadcpython-eeb5635843810ee67f2b18b96f4266d134d913ee.zip
cpython-eeb5635843810ee67f2b18b96f4266d134d913ee.tar.gz
cpython-eeb5635843810ee67f2b18b96f4266d134d913ee.tar.bz2
Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when filename points to a pyc/pyo file and closeit is false.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 05dfb8e..7e9f654 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1385,7 +1385,7 @@ 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, close_own_fp = 0, ret;
size_t len;
m = PyImport_AddModule("__main__");
@@ -1419,6 +1419,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
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 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
Py_DECREF(v);
ret = 0;
done:
+ if (close_own_fp) {
+ fclose(fp);
+ }
if (set_file_name && PyDict_DelItemString(d, "__file__"))
PyErr_Clear();
return ret;