From 953d2422b35b1fc73f32bba3366f07e18577a54b Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Sun, 10 Sep 2017 16:53:02 +0200 Subject: [PATCH] Fix a reference leak in the number converter (#1078) Fixes #1075. `PyNumber_Float()` and `PyNumber_Long()` return new references. --- docs/changelog.rst | 3 +++ include/pybind11/cast.h | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 612a0a66d..eea15d548 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,6 +17,9 @@ v2.2.1 (Not yet released) * Fixed compilation with Clang on host GCC < 5 (old libstdc++ which isn't fully C++11 compliant). `#1062 `_. +* Fixed a reference leak in the number converter. + `#1078 `_. + * Fixed a regression where the automatic ``std::vector`` caster would fail to compile. The same fix also applies to any container which returns element proxies instead of references. diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 3bd1b929b..eab904bee 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -964,9 +964,9 @@ public: ); PyErr_Clear(); if (type_error && convert && PyNumber_Check(src.ptr())) { - auto tmp = reinterpret_borrow(std::is_floating_point::value - ? PyNumber_Float(src.ptr()) - : PyNumber_Long(src.ptr())); + auto tmp = reinterpret_steal(std::is_floating_point::value + ? PyNumber_Float(src.ptr()) + : PyNumber_Long(src.ptr())); PyErr_Clear(); return load(tmp, false); }