Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 735e3b1

Browse files
committed
Merged revisions 85982 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent d9f3f08 commit 735e3b1

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/test/test_fileio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def testTruncate(self):
342342
f.truncate(15)
343343
self.assertEqual(f.tell(), 5)
344344
self.assertEqual(f.seek(0, os.SEEK_END), 15)
345+
f.close()
345346

346347
def testTruncateOnWindows(self):
347348
def bug801631():

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ C-API
143143
Library
144144
-------
145145

146+
- Issue #10253: FileIO leaks a file descriptor when trying to open a file
147+
for append that isn't seekable. Patch by Brian Brazil.
148+
146149
- Issue #5027: The standard ``xml`` namespace is now understood by
147150
xml.sax.saxutils.XMLGenerator as being bound to
148151
http://www.w3.org/XML/1998/namespace. Patch by Troy J. Farrell.

Modules/_io/fileio.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,13 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
364364
end of file (otherwise, it might be done only on the
365365
first write()). */
366366
PyObject *pos = portable_lseek(self->fd, NULL, 2);
367-
if (pos == NULL)
367+
if (pos == NULL) {
368+
if (closefd) {
369+
close(self->fd);
370+
self->fd = -1;
371+
}
368372
goto error;
373+
}
369374
Py_DECREF(pos);
370375
}
371376

0 commit comments

Comments
 (0)