summaryrefslogtreecommitdiffstats
path: root/Modules/_io/fileio.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-30 16:19:14 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-30 16:19:14 (GMT)
commit8d2b51b46a1ba0e09f7ee8cb78c848768a675604 (patch)
tree401ea84f8c345a7f5727db61261109ab9efd8798 /Modules/_io/fileio.c
parentdaf83acf003466777db394cb5e41d72ee6aea035 (diff)
downloadcpython-8d2b51b46a1ba0e09f7ee8cb78c848768a675604.zip
cpython-8d2b51b46a1ba0e09f7ee8cb78c848768a675604.tar.gz
cpython-8d2b51b46a1ba0e09f7ee8cb78c848768a675604.tar.bz2
Issue #10253: FileIO leaks a file descriptor when trying to open a file
for append that isn't seekable. Patch by Brian Brazil.
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r--Modules/_io/fileio.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 16b98d6..279df34 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -396,8 +396,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);
}