mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
#4841: Fix FileIO constructor to honor closefd when called repeatedly
Patch by Victor Stinner.
This commit is contained in:
parent
1a01ebc41c
commit
2cc7156515
2 changed files with 20 additions and 3 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue