diff options
author | Cody Maloney <cmaloney@users.noreply.github.com> | 2024-11-01 21:50:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-01 21:50:49 (GMT) |
commit | 72dd4714f944e5927656aa25f5cd9bdcd3b00a76 (patch) | |
tree | 965ced6971f92758a31d3f37e6625d7048861d62 /Modules/_io/fileio.c | |
parent | c84a136511c673f495f466887716b55c13b7e3ac (diff) | |
download | cpython-72dd4714f944e5927656aa25f5cd9bdcd3b00a76.zip cpython-72dd4714f944e5927656aa25f5cd9bdcd3b00a76.tar.gz cpython-72dd4714f944e5927656aa25f5cd9bdcd3b00a76.tar.bz2 |
gh-120754: _io Ensure stat cache is cleared on fd change (#125166)
Performed an audit of `fileio.c` and `_pyio` and made sure anytime the
fd changes the stat result, if set, is also cleared/changed.
There's one case where it's not cleared, if code would clear it in
__init__, keep the memory allocated and just do another fstat with the
existing memory.
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r-- | Modules/_io/fileio.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index f374592..cf0f1d6 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -131,6 +131,8 @@ internal_close(fileio *self) _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } + PyMem_Free(self->stat_atopen); + self->stat_atopen = NULL; if (err < 0) { errno = save_errno; PyErr_SetFromErrno(PyExc_OSError); @@ -268,8 +270,9 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode, if (self->fd >= 0) { if (self->closefd) { /* Have to close the existing file first. */ - if (internal_close(self) < 0) + if (internal_close(self) < 0) { return -1; + } } else self->fd = -1; @@ -523,10 +526,8 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode, internal_close(self); _PyErr_ChainExceptions1(exc); } - if (self->stat_atopen != NULL) { - PyMem_Free(self->stat_atopen); - self->stat_atopen = NULL; - } + PyMem_Free(self->stat_atopen); + self->stat_atopen = NULL; done: #ifdef MS_WINDOWS |