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

christian.heimes python-checkins at python.org
Tue Sep 11 14:12:35 CEST 2012


http://hg.python.org/cpython/rev/4754c4a710e6
changeset:   78990:4754c4a710e6
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:
  Misc/NEWS          |  3 +++
  Python/pythonrun.c |  6 +++++-
  2 files changed, 8 insertions(+), 1 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when
+  filename points to a pyc/pyo file and closeit is false.
+
 - Issue #15900: Fix reference leak in PyUnicode_TranslateCharmap().
 
 - Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
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