Default `take_ownership` Hazard: Double-Free Risks

Pybind11's default `automatic` policy often defaults to `take_ownership` for raw pointers, risking double-free errors if the C++ side also manages the object's `shared_ptr` lifetime. This can lead to crashes unless `std::enable_shared_from_this` is implemented or `std::shared_ptr` is explicitly returned.

Sources

Open the full topic