diff options
-rw-r--r-- | Lib/test/test_fileio.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 7 |
3 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index cb6ec8e..a63ba06 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -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(): @@ -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 diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index a2a5f73..a685b13 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -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); } |