Search code examples
memory-leaksaddress-sanitizer

How to suppress address sanitizer leak check for specific leak


I'm trying to use asan for a specific compiler version for a program build on Debian bookworm amd64.

The trouble is that the program calls into OpenSSL which in turn uses strerror_l before even encountering any error. But for that purpose a buffer is malloc'ed and never free'd. Hence asan reports a leak:

=================================================================
==3284474==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 17 byte(s) in 1 object(s) allocated from:
    #0 0x7f2515706d68 in __interceptor_malloc /home/tjahns/Documents/work/dkrz/build/spack/var/spack/stage/gcc-9.1.0-d3fldzlztdy4oau2lmzej6g5f23wkioy/spack-src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f251089d427  (/lib/x86_64-linux-gnu/libc.so.6+0x7e427)
    #2 0x7f2510870bd5 in __asprintf (/lib/x86_64-linux-gnu/libc.so.6+0x51bd5)
    #3 0x7f25108bd9f0 in strerror_l (/lib/x86_64-linux-gnu/libc.so.6+0x9e9f0)
    #4 0x7f250f134895 in ERR_load_ERR_strings (/lib/x86_64-linux-gnu/libcrypto.so.1.0.2+0x134895)
    #5 0x7f250f135b08 in ERR_load_crypto_strings (/lib/x86_64-linux-gnu/libcrypto.so.1.0.2+0x135b08)
    #6 0x7f250f641ab8 in SSL_load_error_strings (/lib/x86_64-linux-gnu/libssl.so.1.0.2+0x41ab8)
[...unrelated function calls from the program left out]
SUMMARY: AddressSanitizer: 17 byte(s) leaked in 1 allocation(s).

Since I don't know how to make strerror_l release that buffer, I was wandering if there is a way to suppress this specific leak as there is for valgrind.

I can of course forego all leak checking, but I'd rather have it modulo the one leak above I can't do much about.

Any suggestions to prevent disabling of leak checks completely appreciated. Probably doesn't matter, but the program in question is written in C.


Solution

  • Turns out, the suppression mechanism for leak sanitizer is different from asan:

    printf "%s\n" 'leak:strerror_l' >"suppFile"
    export LSAN_OPTIONS="exitcode=0:fast_unwind_on_malloc=0:suppressions=suppFile:print_suppressions=0"
    

    gives what I wanted.