]> granicus.if.org Git - python/commitdiff
Issue #14505: Fix file descriptor leak when deallocating file objects created with...
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 5 Apr 2012 12:07:52 +0000 (14:07 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 5 Apr 2012 12:07:52 +0000 (14:07 +0200)
Misc/NEWS
Objects/fileobject.c

index 8593a10b1ce0c99ac2c7798751134f1f18b18a70..330477e6557689b1b8022c35901b32dfa24c627c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
 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.
 
index 050e239c4f3440ce175151b1d349503e964a048b..1d8142e17c5982eeb118c69bedbe3c92cbcd81fa 100644 (file)
@@ -493,9 +493,10 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
 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);