Index: textio.c =================================================================== --- textio.c (revision 195883) +++ textio.c (working copy) @@ -1073,10 +1073,12 @@ } static int -_textiowrapper_clear(textio *self) +_textiowrapper_clear(textio *self, int untrack) { if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0) return -1; + if (untrack) + _PyObject_GC_UNTRACK(self); self->ok = 0; Py_CLEAR(self->buffer); Py_CLEAR(self->encoding); @@ -1094,9 +1096,8 @@ static void textiowrapper_dealloc(textio *self) { - if (_textiowrapper_clear(self) < 0) + if (_textiowrapper_clear(self, 1) < 0) return; - _PyObject_GC_UNTRACK(self); if (self->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *)self); Py_CLEAR(self->dict); @@ -1124,7 +1125,7 @@ static int textiowrapper_clear(textio *self) { - if (_textiowrapper_clear(self) < 0) + if (_textiowrapper_clear(self, 0) < 0) return -1; Py_CLEAR(self->dict); return 0;