Advertisement
Advanced C++, Memory Management

What tools help detect memory errors in C++?

Short answer

Tools include AddressSanitizer (ASan) and MemorySanitizer for use-after-free, buffer overflows, and uninitialized reads; Valgrind (Memcheck) for leaks and invalid access; LeakSanitizer for leaks; and static analyzers (clang-tidy, cppcheck).

Save C++ mock interview
Advertisement
AModel answer
Tools include AddressSanitizer (ASan) and MemorySanitizer for use-after-free, buffer overflows, and uninitialized reads; Valgrind (Memcheck) for leaks and invalid access; LeakSanitizer for leaks; and static analyzers (clang-tidy, cppcheck). They're run in testing/CI to catch memory bugs that don't always crash deterministically.
g++ -fsanitize=address -g prog.cpp && ./a.out
Real-world example
Running the test suite under AddressSanitizer in CI catches a use-after-free before release.
Likely follow-ups
  • What does AddressSanitizer detect? | Why run these in CI?
Related topics