changeset: 104886:91f024fc9b3a branch: 2.7 parent: 104883:c0a0abce38f2 user: Serhiy Storchaka date: Thu Nov 03 15:36:50 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 c0a0abce38f2 -r 91f024fc9b3a Misc/ACKS --- a/Misc/ACKS Wed Nov 02 16:20:20 2016 -0400 +++ b/Misc/ACKS Thu Nov 03 15:36:50 2016 +0200 @@ -296,6 +296,7 @@ Felipe Cruz Drew Csillag Joaquin Cuenca Abela +Sebastian Cufre John Cugini Tom Culliton Antonio Cuni diff -r c0a0abce38f2 -r 91f024fc9b3a Misc/NEWS --- a/Misc/NEWS Wed Nov 02 16:20:20 2016 -0400 +++ b/Misc/NEWS Thu Nov 03 15:36:50 2016 +0200 @@ -60,6 +60,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. + - 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 it had 50% chance failed with ignore_zeros=True. diff -r c0a0abce38f2 -r 91f024fc9b3a Modules/_io/textio.c --- a/Modules/_io/textio.c Wed Nov 02 16:20:20 2016 -0400 +++ b/Modules/_io/textio.c Thu Nov 03 15:36:50 2016 +0200 @@ -1071,11 +1071,9 @@ return -1; } -static int +static void _textiowrapper_clear(textio *self) { - if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0) - return -1; self->ok = 0; Py_CLEAR(self->buffer); Py_CLEAR(self->encoding); @@ -1087,18 +1085,19 @@ Py_CLEAR(self->snapshot); Py_CLEAR(self->errors); Py_CLEAR(self->raw); - return 0; + + Py_CLEAR(self->dict); } static void textiowrapper_dealloc(textio *self) { - if (_textiowrapper_clear(self) < 0) + if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0) return; _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); } @@ -1123,9 +1122,9 @@ static int textiowrapper_clear(textio *self) { - if (_textiowrapper_clear(self) < 0) + if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0) return -1; - Py_CLEAR(self->dict); + _textiowrapper_clear(self); return 0; }