Skip to content

Commit d20fb13

Browse files
committed
gh-146102: Fix type slot_bf_getbuffer() error handling
Call PyBuffer_Release() if PyObject_GC_New() fails. Fix also bytes_join(): only call Py_DECREF(item) after formatting the error message which uses item.
1 parent 72e7edd commit d20fb13

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

Objects/stringlib/join.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
7272
drops the sequence's last reference to it. */
7373
Py_INCREF(item);
7474
if (PyObject_GetBuffer(item, &buffers[i], PyBUF_SIMPLE) != 0) {
75-
Py_DECREF(item);
7675
PyErr_Format(PyExc_TypeError,
7776
"sequence item %zd: expected a bytes-like object, "
7877
"%.80s found",
7978
i, Py_TYPE(item)->tp_name);
79+
Py_DECREF(item);
8080
goto error;
8181
}
8282
Py_DECREF(item);

Objects/typeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11327,6 +11327,7 @@ slot_bf_getbuffer(PyObject *self, Py_buffer *buffer, int flags)
1132711327

1132811328
wrapper = PyObject_GC_New(PyBufferWrapper, &_PyBufferWrapper_Type);
1132911329
if (wrapper == NULL) {
11330+
PyBuffer_Release(buffer);
1133011331
goto fail;
1133111332
}
1133211333
wrapper->mv = ret;

0 commit comments

Comments
 (0)