This a quick example for how to use the address sanitizer to discover various programming errors in C and C++.
https://code.google.com/p/address-sanitizer/wiki/ComparisonOfMemoryTools http://btorpey.github.io/blog/2014/03/27/using-clangs-address-sanitizer/
On OSX, address-sanitizer currently requires a custom build of clang:
- See https://code.google.com/p/address-sanitizer/wiki/HowToBuild
- Add compiler-rt and libcxx to llvm's projects/ dir
- Run cmake with: CC=/your/custom/llvm-build/bin/clang CXX=/your-custom/llvm-build/bin/clang++ cmake ../src_dir/
This project includes a CMakeLists.txt file that should let you get started. Steps:
git clone https://github.com/Stanback/asan-demo.git
mkdir build
cmake ../asan-demo
make
./leak-demo