[Python-checkins] cpython: Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when filename

georg.brandl python-checkins at python.org
Mon Sep 24 07:46:51 CEST 2012


http://hg.python.org/cpython/rev/fe4e6e0d6b0f
changeset: 79109:fe4e6e0d6b0f
parent: 78920:72598063c6c4
user: Christian Heimes <christian at cheimes.de>
date: Tue Sep 11 14:11:03 2012 +0200
summary:
 Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when filename points to a pyc/pyo file and closeit is false.
files:
 Python/pythonrun.c | 6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /