#4841: Fix FileIO constructor to honor closefd when called repeatedly
Patch by Victor Stinner.
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 0048240..d1941df 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -198,9 +198,13 @@
assert(PyFileIO_Check(oself));
if (self->fd >= 0) {
- /* Have to close the existing file first. */
- if (internal_close(self) < 0)
- return -1;
+ if (self->closefd) {
+ /* Have to close the existing file first. */
+ if (internal_close(self) < 0)
+ return -1;
+ }
+ else
+ self->fd = -1;
}
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|si:fileio",