From aa4113bf956e9f58b05495ae4aafa124ebfa0341 Mon Sep 17 00:00:00 2001 From: Blistic Date: Sun, 4 Nov 2018 13:17:23 +0000 Subject: [PATCH 1/2] Fix deallocation of incorrect pointer (#1568) --- include/pybind11/detail/class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 7a5dd0130d..40551290b7 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -222,7 +222,7 @@ inline bool deregister_instance_impl(void *ptr, instance *self) { auto ®istered_instances = get_internals().registered_instances; auto range = registered_instances.equal_range(ptr); for (auto it = range.first; it != range.second; ++it) { - if (Py_TYPE(self) == Py_TYPE(it->second)) { + if (self == it->second) { registered_instances.erase(it); return true; } From 37c1c2684ad2ac7dbf794fd8143f6b036776fda2 Mon Sep 17 00:00:00 2001 From: Blistic Date: Sun, 4 Nov 2018 13:51:41 +0000 Subject: [PATCH 2/2] Fix #1568 --- include/pybind11/detail/class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 40551290b7..10456ec209 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -222,7 +222,7 @@ inline bool deregister_instance_impl(void *ptr, instance *self) { auto ®istered_instances = get_internals().registered_instances; auto range = registered_instances.equal_range(ptr); for (auto it = range.first; it != range.second; ++it) { - if (self == it->second) { + if (Py_TYPE(self) == Py_TYPE(it->second) && self == it->second) { registered_instances.erase(it); return true; }