Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Modules/_io/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,10 @@ stringio_getstate(stringio *self)
}
else {
dict = PyDict_Copy(self->dict);
if (dict == NULL)
if (dict == NULL) {
Py_DECREF(initvalue);
return NULL;
}
}

state = Py_BuildValue("(OOnN)", initvalue,
Expand Down
21 changes: 14 additions & 7 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1773,11 +1773,16 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
*/
PyObject *next_input = dec_buffer;
PyBytes_Concat(&next_input, input_chunk);
dec_buffer = NULL; /* Reference lost to PyBytes_Concat */
if (next_input == NULL) {
dec_buffer = NULL; /* Reference lost to PyBytes_Concat */
goto fail;
}
Py_XSETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input));
PyObject *snapshot = Py_BuildValue("NN", dec_flags, next_input);
if (snapshot == NULL) {
dec_flags = NULL;
goto fail;
}
Py_XSETREF(self->snapshot, snapshot);
}
Py_DECREF(input_chunk);

Expand Down Expand Up @@ -2326,6 +2331,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
cookie_type cookie;
PyObject *res;
int cmp;
PyObject *snapshot;

CHECK_ATTACHED(self);
CHECK_CLOSED(self);
Expand Down Expand Up @@ -2460,11 +2466,11 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail;
}

self->snapshot = Py_BuildValue("iN", cookie.dec_flags, input_chunk);
if (self->snapshot == NULL) {
Py_DECREF(input_chunk);
snapshot = Py_BuildValue("iN", cookie.dec_flags, input_chunk);
if (snapshot == NULL) {
goto fail;
}
Py_XSETREF(self->snapshot, snapshot);

decoded = _PyObject_CallMethodId(self->decoder, &PyId_decode,
"Oi", input_chunk, (int)cookie.need_eof);
Expand All @@ -2482,9 +2488,10 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
self->decoded_chars_used = cookie.chars_to_skip;
}
else {
self->snapshot = Py_BuildValue("iy", cookie.dec_flags, "");
if (self->snapshot == NULL)
snapshot = Py_BuildValue("iy", cookie.dec_flags, "");
if (snapshot == NULL)
goto fail;
Py_XSETREF(self->snapshot, snapshot);
}

/* Finally, reset the encoder (merely useful for proper BOM handling) */
Expand Down