Pretty much everything here can be avoided by using smart pointers. Unfortunately so many C++ libraries do not use these so the safety breaks at this point.
And when using C libraries... well Rust will have the same issue, you need to make wrappers, and if these have faults, you get dangling pointers and unhappiness like that :(