We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a24957d commit c2cb455Copy full SHA for c2cb455
1 file changed
Modules/_io/textio.c
@@ -1631,11 +1631,14 @@ _io_TextIOWrapper_detach_impl(textio *self)
1631
/*[clinic end generated code: output=7ba3715cd032d5f2 input=c908a3b4ef203b0f]*/
1632
{
1633
PyObject *buffer;
1634
- CHECK_ATTACHED(self);
1635
if (_PyFile_Flush((PyObject *)self) < 0) {
1636
return NULL;
1637
}
1638
- buffer = self->buffer;
+ /* _PyFile_Flush could detach before returning; raise an exception. */
+ buffer = buffer_access_safe(self);
1639
+ if (buffer == NULL) {
1640
+ return NULL;
1641
+ }
1642
self->buffer = NULL;
1643
self->detached = 1;
1644
return buffer;
0 commit comments