Try   HackMD

Address Sanitizer (ASan)

What is "Address Sanitizer"?

Address Sanitizer is a tool for detection memory error, like stack over flow, buffer over follw, memory leaketc.

How to use it ?

  1. set the compiler flag
    ​​​​-fsanitize=address -fno-omit-frame-pointer
    ​​​​-fsanitize=address
    
  2. including the LSan, so when you enable ASan, the LSan also be enabled.

    You can use
    ASAN_OPTIONS=detect_leaks=1 to enable it
    ASAN_OPTIONS=detect_leaks=0 to disenable it

    Here are others options:
    • halt_on_error=0:non-stop when memory happens
    • malloc_context_size=15
    • log_path=/path/to/logfile
    • suppressions=$SUPP_FILE
  3. running the code
    ​​​​LD_PRELOAD=/path/to/Asanlib.so ./test_program
    
    or add -static-libasan for static library into the target program

How to work

ref