Have you tried compiling with address sanitizer?
https://clang.llvm.org/docs/AddressSanitizer.html
Unfortunately C++ code is only portable if it is free from undefined behavior. Fortunately there are many tools now to debug these kinds of errors: https://blog.regehr.org/archives/1520