Skip to content

Commit dd3f975

Browse files
committed
Address cmaloney's review
Move PyBytesWriter_Create() call
1 parent 2ca682e commit dd3f975

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Modules/_io/bufferedio.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,25 +1048,26 @@ _io__Buffered_read1_impl(buffered *self, Py_ssize_t n)
10481048
return res;
10491049
}
10501050

1051-
PyBytesWriter *writer = PyBytesWriter_Create(n);
1052-
if (writer == NULL) {
1053-
return NULL;
1054-
}
10551051
if (!ENTER_BUFFERED(self)) {
1056-
PyBytesWriter_Discard(writer);
10571052
return NULL;
10581053
}
1054+
10591055
/* Flush the write buffer if necessary */
10601056
if (self->writable) {
10611057
PyObject *res = buffered_flush_and_rewind_unlocked(self);
10621058
if (res == NULL) {
10631059
LEAVE_BUFFERED(self)
1064-
PyBytesWriter_Discard(writer);
10651060
return NULL;
10661061
}
10671062
Py_DECREF(res);
10681063
}
10691064
_bufferedreader_reset_buf(self);
1065+
1066+
PyBytesWriter *writer = PyBytesWriter_Create(n);
1067+
if (writer == NULL) {
1068+
return NULL;
1069+
}
1070+
10701071
Py_ssize_t r = _bufferedreader_raw_read(self,
10711072
PyBytesWriter_GetData(writer), n);
10721073
LEAVE_BUFFERED(self)

0 commit comments

Comments
 (0)