You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After interfacing with a c++ PQTree library: https://github.com/Gregable/pq-trees
and after calling methods from the PQTree library in python i always get C++ segfaults after the Python interpreter shuts down
This is mostly 'double free or corruption (out)' but also general segfaults.
we noticed that everything in our python function is executed, but after the call to the function, the errors appear (probably because the C++ destructors are called and the error occurs there).
The initial intuition is that:
somewhere, both a pybind11 object and C++ think they own a pointer, and the garbage collector is deleting the pybind object PQNode that has probably already been deleted by C++.
is there any way to prevent occurring segfaults (suppress the pyobject deletion by the garbage collector if it was already freed in c++ by the destructor)?
@bstaletic and I have been debugging with you on Gitter. The preliminary conclusion was that (most likely) pybind11 is taking ownership of one of your pointers and that it is deleting them after C++.
I asked you to add print functionality to your destructor to further debug, and you never did that or told us what you got.
Handle this like any other case in C++ where two things delete the same thing: figure out which part of the program shóuld own the code, and make sure the other one doesn't delete it. Also read about pybind11's return_value_policy, if you want pybind11 to not take ownership of a returned pointer.
The issue is resolved,
it was a memory management issue (an overlap between the python gc and the cpp destructor) which lead to freeing the same pyobject twice
in order to solve it we have resolved to the following
in case of class with init use py::nodelete to make sure Python never deletes any objects of that exact type in question
in case of a module::def() it is advised to use return_value_policy::copy
After interfacing with a c++ PQTree library: https://github.com/Gregable/pq-trees
and after calling methods from the PQTree library in python i always get C++ segfaults after the Python interpreter shuts down
The initial intuition is that:
is there any way to prevent occurring segfaults (suppress the pyobject deletion by the garbage collector if it was already freed in c++ by the destructor)?
here is a pastebin to gdb: https://pastebin.com/ifNF6TfW
The text was updated successfully, but these errors were encountered: