Skip to content

Commit c2cb455

Browse files
committed
Fix NULL with no exception after flush in detach
1 parent a24957d commit c2cb455

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Modules/_io/textio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,11 +1631,14 @@ _io_TextIOWrapper_detach_impl(textio *self)
16311631
/*[clinic end generated code: output=7ba3715cd032d5f2 input=c908a3b4ef203b0f]*/
16321632
{
16331633
PyObject *buffer;
1634-
CHECK_ATTACHED(self);
16351634
if (_PyFile_Flush((PyObject *)self) < 0) {
16361635
return NULL;
16371636
}
1638-
buffer = self->buffer;
1637+
/* _PyFile_Flush could detach before returning; raise an exception. */
1638+
buffer = buffer_access_safe(self);
1639+
if (buffer == NULL) {
1640+
return NULL;
1641+
}
16391642
self->buffer = NULL;
16401643
self->detached = 1;
16411644
return buffer;

0 commit comments

Comments
 (0)