Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash (double free) in the :term:`free-threaded build` when ``close()``
or ``truncate()`` is called concurrently on the same unbuffered
:class:`io.FileIO` object.
8 changes: 2 additions & 6 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ internal_close(fileio *self)
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
}
PyMem_Free(self->stat_atopen);
self->stat_atopen = NULL;
PyMem_Free(_Py_atomic_exchange_ptr(&self->stat_atopen, NULL));
if (err < 0) {
errno = save_errno;
PyErr_SetFromErrno(PyExc_OSError);
Expand Down Expand Up @@ -1148,10 +1147,7 @@ _io_FileIO_truncate_impl(fileio *self, PyTypeObject *cls, PyObject *posobj)
/* Since the file was truncated, its size at open is no longer accurate
as an estimate. Clear out the stat result, and rely on dynamic resize
code if a readall is requested. */
if (self->stat_atopen != NULL) {
PyMem_Free(self->stat_atopen);
self->stat_atopen = NULL;
}
PyMem_Free(_Py_atomic_exchange_ptr(&self->stat_atopen, NULL));

return posobj;
}
Expand Down
Loading