[Python-checkins] cpython (2.7): Issue #14505: Fix file descriptor leak when deallocating file objects created

antoine.pitrou python-checkins at python.org
Thu Apr 5 14:13:21 CEST 2012


http://hg.python.org/cpython/rev/8258e5fa4a19
changeset:   76117:8258e5fa4a19
branch:      2.7
parent:      76113:4416efeb0163
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Thu Apr 05 14:07:52 2012 +0200
summary:
  Issue #14505: Fix file descriptor leak when deallocating file objects created with PyFile_FromString().

files:
  Misc/NEWS            |  3 +++
  Objects/fileobject.c |  3 ++-
  2 files changed, 5 insertions(+), 1 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
 Core and Builtins
 -----------------
 
+- Issue #14505: Fix file descriptor leak when deallocating file objects
+  created with PyFile_FromString().
+
 - Issue #14474: Save and restore exception state in thread.start_new_thread()
   while writing error message if the thread leaves a unhandled exception.
 
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -493,9 +493,10 @@
 PyObject *
 PyFile_FromString(char *name, char *mode)
 {
+    extern int fclose(FILE *);
     PyFileObject *f;
 
-    f = (PyFileObject *)PyFile_FromFile((FILE *)NULL, name, mode, NULL);
+    f = (PyFileObject *)PyFile_FromFile((FILE *)NULL, name, mode, fclose);
     if (f != NULL) {
         if (open_the_file(f, name, mode) == NULL) {
             Py_DECREF(f);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list