Memory Safety in C++ is not really possible.
Here is why: https://sappeur.di-fg.de/WhyCandCppCannotBeMemorySafe.html
The best you can do is to be very disciplined, follow KISS and use modern C++.