Kaydet (Commit) 52b0888d authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when

the garbage collector is invoked in other thread.
Based on patch by Sebastian Cufre.
üst d01b516e
...@@ -296,6 +296,7 @@ Simon Cross ...@@ -296,6 +296,7 @@ Simon Cross
Felipe Cruz Felipe Cruz
Drew Csillag Drew Csillag
Joaquin Cuenca Abela Joaquin Cuenca Abela
Sebastian Cufre
John Cugini John Cugini
Tom Culliton Tom Culliton
Antonio Cuni Antonio Cuni
......
...@@ -60,6 +60,10 @@ Core and Builtins ...@@ -60,6 +60,10 @@ Core and Builtins
Library Library
------- -------
- Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when
the garbage collector is invoked in other thread. Based on patch by
Sebastian Cufre.
- Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar - Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
file with compression before trying to open it without compression. Otherwise file with compression before trying to open it without compression. Otherwise
it had 50% chance failed with ignore_zeros=True. it had 50% chance failed with ignore_zeros=True.
......
...@@ -1071,11 +1071,9 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds) ...@@ -1071,11 +1071,9 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
return -1; return -1;
} }
static int static void
_textiowrapper_clear(textio *self) _textiowrapper_clear(textio *self)
{ {
if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
return -1;
self->ok = 0; self->ok = 0;
Py_CLEAR(self->buffer); Py_CLEAR(self->buffer);
Py_CLEAR(self->encoding); Py_CLEAR(self->encoding);
...@@ -1087,18 +1085,19 @@ _textiowrapper_clear(textio *self) ...@@ -1087,18 +1085,19 @@ _textiowrapper_clear(textio *self)
Py_CLEAR(self->snapshot); Py_CLEAR(self->snapshot);
Py_CLEAR(self->errors); Py_CLEAR(self->errors);
Py_CLEAR(self->raw); Py_CLEAR(self->raw);
return 0;
Py_CLEAR(self->dict);
} }
static void static void
textiowrapper_dealloc(textio *self) textiowrapper_dealloc(textio *self)
{ {
if (_textiowrapper_clear(self) < 0) if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
return; return;
_PyObject_GC_UNTRACK(self); _PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL) if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)self); PyObject_ClearWeakRefs((PyObject *)self);
Py_CLEAR(self->dict); _textiowrapper_clear(self);
Py_TYPE(self)->tp_free((PyObject *)self); Py_TYPE(self)->tp_free((PyObject *)self);
} }
...@@ -1123,9 +1122,9 @@ textiowrapper_traverse(textio *self, visitproc visit, void *arg) ...@@ -1123,9 +1122,9 @@ textiowrapper_traverse(textio *self, visitproc visit, void *arg)
static int static int
textiowrapper_clear(textio *self) textiowrapper_clear(textio *self)
{ {
if (_textiowrapper_clear(self) < 0) if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
return -1; return -1;
Py_CLEAR(self->dict); _textiowrapper_clear(self);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment