Issue #13070: Fix a crash when a TextIOWrapper caught in a reference cycle

would be finalized after the reference to its underlying BufferedRWPair's
writer got cleared by the GC.
This commit is contained in:
Charles-François Natali 2011-10-05 19:55:56 +02:00
commit b619bb27ed
3 changed files with 24 additions and 0 deletions

View file

@ -2307,6 +2307,11 @@ bufferedrwpair_isatty(rwpair *self, PyObject *args)
static PyObject *
bufferedrwpair_closed_get(rwpair *self, void *context)
{
if (self->writer == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"the BufferedRWPair object is being garbage-collected");
return NULL;
}
return PyObject_GetAttr((PyObject *) self->writer, _PyIO_str_closed);
}