From a76ed42c3f828bcb89422bdeb984194579841686 Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Tue, 14 Feb 2017 01:43:20 +0100 Subject: [PATCH] Fix sequence_item reference leak (#660) --- include/pybind11/pytypes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index ae0ad780e..e44f8ac5b 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -254,7 +254,7 @@ public: .. code-block:: cpp - PyObject *result = PySequence_GetItem(obj, index); + PyObject *p = PyList_GetItem(obj, index); py::object o = reinterpret_borrow(p); // or py::tuple t = reinterpret_borrow(p); // <-- `p` must be already be a `tuple` @@ -453,7 +453,7 @@ struct sequence_item { static object get(handle obj, size_t index) { PyObject *result = PySequence_GetItem(obj.ptr(), static_cast(index)); if (!result) { throw error_already_set(); } - return reinterpret_borrow(result); + return reinterpret_steal(result); } static void set(handle obj, size_t index, handle val) {