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.
"""
if self._fd >= 0:
# Have to close the existing file first.
+ self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
if e.errno != errno.ESPIPE:
raise
except:
+ self._stat_atopen = None
if owned_fd is not None:
os.close(owned_fd)
raise
called more than once without error.
"""
if not self.closed:
+ self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
_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);
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;
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