Fix a reference leak in the number converter (#1078)

Fixes #1075.

`PyNumber_Float()` and `PyNumber_Long()` return new references.
This commit is contained in:
Dean Moldovan 2017-09-10 16:53:02 +02:00 committed by Wenzel Jakob
parent 7b1de1e551
commit 953d2422b3
2 changed files with 6 additions and 3 deletions

View File

@ -17,6 +17,9 @@ v2.2.1 (Not yet released)
* Fixed compilation with Clang on host GCC < 5 (old libstdc++ which isn't fully * Fixed compilation with Clang on host GCC < 5 (old libstdc++ which isn't fully
C++11 compliant). `#1062 <https://github.com/pybind/pybind11/pull/1062>`_. C++11 compliant). `#1062 <https://github.com/pybind/pybind11/pull/1062>`_.
* Fixed a reference leak in the number converter.
`#1078 <https://github.com/pybind/pybind11/pull/1078>`_.
* Fixed a regression where the automatic ``std::vector<bool>`` caster would * Fixed a regression where the automatic ``std::vector<bool>`` caster would
fail to compile. The same fix also applies to any container which returns fail to compile. The same fix also applies to any container which returns
element proxies instead of references. element proxies instead of references.

View File

@ -964,9 +964,9 @@ public:
); );
PyErr_Clear(); PyErr_Clear();
if (type_error && convert && PyNumber_Check(src.ptr())) { if (type_error && convert && PyNumber_Check(src.ptr())) {
auto tmp = reinterpret_borrow<object>(std::is_floating_point<T>::value auto tmp = reinterpret_steal<object>(std::is_floating_point<T>::value
? PyNumber_Float(src.ptr()) ? PyNumber_Float(src.ptr())
: PyNumber_Long(src.ptr())); : PyNumber_Long(src.ptr()));
PyErr_Clear(); PyErr_Clear();
return load(tmp, false); return load(tmp, false);
} }