AddressSanitizer is a fast alternative of
Valgrind for memory error check. It based on a totally different mechanism that substitute all the memory allocation and free functions in your code and keep track all memory operations.
Clang integrated AddressSanitizer since 3.1 version. We can use it directly by adding some compiler flags for Clang.
Something like this:
clang -fsanitize=address -O1 -fno-omit-frame-pointer -g tests.cpp
With CMake projection, however, we need to add the flag in your make file.
The simplest thing would be to add the following in your make file:
set(CMAKE_CXX_FLAGS "-fsanitize=address -O1 -fno-omit-frame-pointer -g")