Issue #10253: FileIO leaks a file descriptor when trying to open a file
for append that isn't seekable. Patch by Brian Brazil.
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 @@
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);
}