summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-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 f332ee4633..a365c9fe46 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -364,8 +364,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);
}