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.
How to suppress LeakSanitizer report when running under -fsanitize=address?
Asked Answered
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.
Unfortunately, there is no "detect_leaks" in the spec provided... –
Snelling
@AlexandrDerkach You mean
detect_leaks
is not mentioned in wiki? Yes, that is unfortunate, I wish someone fixed that wikipage. –
Cary Yes. But I've found it like inside this spec: link –
Snelling
@AlexandrDerkach Ah, so they moved the description. I've updated the answer, thank you. –
Cary
Adding a note: this also works in C++, if you prepend extern "C". –
Variegation
@Variegation Oh, right, added this to the answer. –
Cary
© 2022 - 2024 — McMap. All rights reserved.
-fsanitize=address
if you don't want his report – Nadiya