You might want to give a shot to address-sanitizer. It is available in gcc 4.8:
AddressSanitizer , a fast memory error detector, has been added and can be enabled via
-fsanitize=address
. Memory access instructions will be instrumented to detect heap-, stack-, and global-buffer overflow as well as use-after-free bugs. To get nicer stacktraces, use-fno-omit-frame-pointer
. The AddressSanitizer is available on IA-32/x86-64/x32/PowerPC/PowerPC64 GNU/Linux and on x86-64 Darwin.
In GCC (but apparently not clang), you need to specify -fsanitize=address
in both the compiler flags and linker flags, as described in this related answer.