Skip to content
Snippets Groups Projects
Commit b84692c9 authored by Olivier BICHLER's avatar Olivier BICHLER Committed by Maxence Naud
Browse files

Fixed possible segfault at exist

parent a54064b1
No related branches found
No related tags found
3 merge requests!279v0.4.0,!253v0.4.0,!208DynamicAttributes refactor
......@@ -277,7 +277,21 @@ public:
return mAttrs;
}
virtual ~DynamicAttributes() {}
virtual ~DynamicAttributes() {
#ifdef PYBIND
if (!Py_IsInitialized()) {
// Resets the internal pointer of py::object to nullptr without decreasing the object's reference count.
// At this point, the Python interpreter may have exited (it is the case if the current DynamicAttribute being destroyed is static),
// in which case py:object has already being destroyed despite the reference counting being > 0.
// See https://github.com/pybind/pybind11/issues/1598
for (auto& attr : mAttrs) {
if (attr.second.type() == typeid(py::object)) {
future_std::any_cast<py::object&>(attr.second).release();
}
}
}
#endif
}
friend bool operator<(const DynamicAttributes& lhs, const DynamicAttributes& rhs);
friend struct std::hash<DynamicAttributes>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment