]> granicus.if.org Git - python/commitdiff
Merged revisions 85982 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 31 Oct 2010 13:05:48 +0000 (13:05 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 31 Oct 2010 13:05:48 +0000 (13:05 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85982 | antoine.pitrou | 2010-10-30 18:19:14 +0200 (sam., 30 oct. 2010) | 4 lines

  Issue #10253: FileIO leaks a file descriptor when trying to open a file
  for append that isn't seekable.  Patch by Brian Brazil.
........

Lib/test/test_fileio.py
Misc/NEWS
Modules/_io/fileio.c

index cb6ec8e02070392d154d4907e0707ded2a40547c..a63ba06bb41e32e1434902b4e14995cb355181a5 100644 (file)
@@ -341,6 +341,7 @@ class OtherFileTests(unittest.TestCase):
         f.truncate(15)
         self.assertEqual(f.tell(), 5)
         self.assertEqual(f.seek(0, os.SEEK_END), 15)
+        f.close()
 
     def testTruncateOnWindows(self):
         def bug801631():
index dc5dca453fbd334bfe6154b16c9e73c203982294..82c0f513a12347b533b57121ce5ef57aea7b5ef5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10253: FileIO leaks a file descriptor when trying to open a file
+  for append that isn't seekable.  Patch by Brian Brazil.
+
 - Issue #6105: json.dumps now respects OrderedDict's iteration order.
 
 - Issue #9295: Fix a crash under Windows when calling close() on a file
index a2a5f737f789861d1061495a2ec04ad07917136e..a685b134a3b9bb66ce3412f3007e453249c5c9f8 100644 (file)
@@ -367,8 +367,13 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
            end of file (otherwise, it might be done only on the
            first write()). */
         PyObject *pos = portable_lseek(self->fd, NULL, 2);
-        if (pos == NULL)
+        if (pos == NULL) {
+            if (closefd) {
+                close(self->fd);
+                self->fd = -1;
+            }
             goto error;
+        }
         Py_DECREF(pos);
     }