#4841: Fix FileIO constructor to honor closefd when called repeatedly

Patch by Victor Stinner.
This commit is contained in:
Hynek Schlawack 2012-05-25 10:05:53 +02:00
parent 1a01ebc41c
commit 2cc7156515
2 changed files with 20 additions and 3 deletions

View file

@ -227,9 +227,13 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
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",