Skip to content

Commit 0ec7c9d

Browse files
authored
gh-146102: Fix type slot_bf_getbuffer() error handling (#151346)
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 b3b7c00 commit 0ec7c9d

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
@@ -11332,6 +11332,7 @@ slot_bf_getbuffer(PyObject *self, Py_buffer *buffer, int flags)
1133211332

1133311333
wrapper = PyObject_GC_New(PyBufferWrapper, &_PyBufferWrapper_Type);
1133411334
if (wrapper == NULL) {
11335+
PyBuffer_Release(buffer);
1133511336
goto fail;
1133611337
}
1133711338
wrapper->mv = ret;

0 commit comments

Comments
 (0)