Skip to content

Commit a76ed42

Browse files
dean0x7dwjakob
authored andcommitted
Fix sequence_item reference leak (#660)
1 parent 5e92b3e commit a76ed42

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class object : public handle {
254254
255255
.. code-block:: cpp
256256
257-
PyObject *result = PySequence_GetItem(obj, index);
257+
PyObject *p = PyList_GetItem(obj, index);
258258
py::object o = reinterpret_borrow<py::object>(p);
259259
// or
260260
py::tuple t = reinterpret_borrow<py::tuple>(p); // <-- `p` must be already be a `tuple`
@@ -453,7 +453,7 @@ struct sequence_item {
453453
static object get(handle obj, size_t index) {
454454
PyObject *result = PySequence_GetItem(obj.ptr(), static_cast<ssize_t>(index));
455455
if (!result) { throw error_already_set(); }
456-
return reinterpret_borrow<object>(result);
456+
return reinterpret_steal<object>(result);
457457
}
458458

459459
static void set(handle obj, size_t index, handle val) {

0 commit comments

Comments
 (0)