From 155cc7c4d29a1d7d1497a63ff70ec374ed80ea69 Mon Sep 17 00:00:00 2001 From: Zach DeVito Date: Thu, 14 Dec 2017 17:19:19 -0800 Subject: [PATCH] Fix leak in var arg handling When using the mixed position + vararg path, pybind over inc_ref's the vararg positions. Printing the ref_count() of `item` before and after this change you see: Before change: ``` refcount of item before assign 3 refcount of item after assign 5 ``` After change ``` refcount of item before assign 3 refcount of item after assign 4 ``` --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 6cedcc262..1a12ed0b5 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -589,7 +589,7 @@ protected: extra_args = tuple(args_size); for (size_t i = 0; i < args_size; ++i) { handle item = PyTuple_GET_ITEM(args_in, args_copied + i); - extra_args[i] = item.inc_ref().ptr(); + extra_args[i] = reinterpret_borrow(item); } } call.args.push_back(extra_args);