The GCC option -fsanitize=address helps detect the following types of errors that may happen in C programs -

  • use after free error
  • heap buffer overflow
    (writing beyond what has been allocated from the heap)
  • stack overflow error
  • memory leaks

This available in GCC ≥ 4.8.

Use the option while compiling your code. The executable must then be executed to catch any errors that -fsanitize helps to catch.

It is useful to add -g as well to the compile command-line to debug any errors that may throw up.

For more information, go to https://github.com/google/sanitizers/wiki/AddressSanitizer

--

--