How to write very detailed suppresion file entry for clang address sanitizer

66 Views Asked by At

I have some test written in gtest which are driven by standard gtest_main function (test target is linking gtest_main).

Problem is that memory leak is reported even if no test is run. For example:

$ ./UnitTests --gtest_filter=NotExistingTest
Note: Google Test filter = NotExistingTest
[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[  PASSED  ] 0 tests.

=================================================================
==26367==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 5000 byte(s) in 72 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x8604f42 in CRYPTO_zalloc (/home/User/repos/Src/Debug/UnitTests+0x8604f42)

Indirect leak of 432 byte(s) in 9 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x86032f5 in ossl_crypto_get_ex_new_index_ex (/home/User/repos/Src/Debug/UnitTests+0x86032f5)

Indirect leak of 208 byte(s) in 2 object(s) allocated from:
    #0 0x72e0c9 in realloc (/home/User/repos/Src/Debug/UnitTests+0x72e0c9)
    #1 0x863697e in sk_reserve (/home/User/repos/Src/Debug/UnitTests+0x863697e)

Indirect leak of 192 byte(s) in 8 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x85ffedb in OPENSSL_LH_insert (/home/User/repos/Src/Debug/UnitTests+0x85ffedb)

Indirect leak of 172 byte(s) in 8 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x861fab4 in ossl_property_string (/home/User/repos/Src/Debug/UnitTests+0x861fab4)

Indirect leak of 128 byte(s) in 4 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x8636507 in OPENSSL_sk_deep_copy (/home/User/repos/Src/Debug/UnitTests+0x8636507)

Indirect leak of 49 byte(s) in 5 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x8606f83 in CRYPTO_strdup (/home/User/repos/Src/Debug/UnitTests+0x8606f83)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x72ddad in malloc (/home/User/repos/Src/Debug/UnitTests+0x72ddad)
    #1 0x861ea37 in stack_to_property_list (/home/User/repos/Src/Debug/UnitTests+0x861ea37)

SUMMARY: AddressSanitizer: 6213 byte(s) leaked in 109 allocation(s).

When I run all test no other leak report looks exactly the same.

Now I'd like to write suppression file which address only those specific leaks.
Clang documentation shows this should be possible, but options show there:

interceptor_via_fun:NameOfCFunctionToSuppress
interceptor_via_fun:-[ClassName objCMethodToSuppress:]
interceptor_via_lib:NameOfTheLibraryToSuppress

are to general and I can miss some actual leaks. I do not want to write in this file for example:

interceptor_via_fun:CRYPTO_zalloc

Since my code can actually use those and have a leak. It would be nice to specify more details about call stack when this happens.

Aim is to use address sanitizer in CI and relay on exit code of unit test application. With this leak present I always gate exit code 1.

I have no idea how to fix those leaks (not call stack is pretty shallow and doesn't point to anything I'm controlling), so if there is a way to fix them it would be great.

The OpenSSL versions where I've see this kind of issue are: 1.1.1g, 3.0.4, 3.0.8. They are custom build as static libraries.

0

There are 0 best solutions below