Search code examples
c++address-sanitizerleak-sanitizer

How to suppress LeakSanitizer report when running under -fsanitize=address?


When I compile my C++ code with -fsanitize=address, my software prints out a list of leaks at the time it exits. Is there a way to avoid the leaks report (I'm only interested in memory corruptions, not leaks)? I went to the page with ASAN flags page, but it doesn't look like any of those flags is a match.


Solution

  • You can run with export ASAN_OPTIONS=detect_leaks=0 or add a function to your application:

    #ifdef __cplusplus
    extern "C"
    #endif
    const char* __asan_default_options() { return "detect_leaks=0"; }
    

    See Asan flags wiki and common sanitizer flags wiki for more details.