changeset: 104888:c4319c0d0131 branch: 3.6 parent: 104884:d1e6b12e33fd parent: 104887:89f7386104e2 user: Serhiy Storchaka date: Thu Nov 03 15:38:17 2016 +0200 files: Misc/ACKS Misc/NEWS Modules/_io/textio.c description: Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when the garbage collector is invoked in other thread. Based on patch by Sebastian Cufre. diff -r d1e6b12e33fd -r c4319c0d0131 Misc/ACKS --- a/Misc/ACKS Wed Nov 02 20:32:37 2016 -0400 +++ b/Misc/ACKS Thu Nov 03 15:38:17 2016 +0200 @@ -321,6 +321,7 @@ Drew Csillag Alessandro Cucci Joaquin Cuenca Abela +Sebastian Cufre John Cugini Tom Culliton Raúl Cumplido diff -r d1e6b12e33fd -r c4319c0d0131 Misc/NEWS --- a/Misc/NEWS Wed Nov 02 20:32:37 2016 -0400 +++ b/Misc/NEWS Thu Nov 03 15:38:17 2016 +0200 @@ -16,6 +16,10 @@ 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. + Documentation ------------- diff -r d1e6b12e33fd -r c4319c0d0131 Modules/_io/textio.c --- a/Modules/_io/textio.c Wed Nov 02 20:32:37 2016 -0400 +++ b/Modules/_io/textio.c Thu Nov 03 15:38:17 2016 +0200 @@ -1103,7 +1103,7 @@ } static int -_textiowrapper_clear(textio *self) +textiowrapper_clear(textio *self) { self->ok = 0; Py_CLEAR(self->buffer); @@ -1116,6 +1116,8 @@ Py_CLEAR(self->snapshot); Py_CLEAR(self->errors); Py_CLEAR(self->raw); + + Py_CLEAR(self->dict); return 0; } @@ -1125,11 +1127,11 @@ self->finalizing = 1; if (_PyIOBase_finalize((PyObject *) self) < 0) return; - _textiowrapper_clear(self); + self->ok = 0; _PyObject_GC_UNTRACK(self); if (self->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *)self); - Py_CLEAR(self->dict); + textiowrapper_clear(self); Py_TYPE(self)->tp_free((PyObject *)self); } @@ -1151,15 +1153,6 @@ return 0; } -static int -textiowrapper_clear(textio *self) -{ - if (_textiowrapper_clear(self) < 0) - return -1; - Py_CLEAR(self->dict); - return 0; -} - static PyObject * textiowrapper_closed_get(textio *self, void *context);