Skip to content

Segfault when dealing with references to objects with multiple base classes / virtual inheritance #4303

Discussion options

You must be logged in to vote

Actually, the bug in the reproducer pointed me to the issue in my original use case.
Having a Python reference / reference_internal to a C++ object that no longer exists is undefined behavior in Pybind11. For this, the reference needs not even be used, as the deregistering routines of Pybind11 for objects with multiple inheritance assume that the object still exists. So, the lifetime of such references must be strictly not large than that of the referenced C++ object.

The bug in the reproducer is that the vector gets reallocated, thus invalidating the old references. They are used no longer, but deregistering the references will still fail.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by franzpoeschel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant