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

1

23

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.

Swellfish answered 27/6, 2018 at 10:44 Comment(4)
Hm, you tell the compiler to add code that checks the correct behavior of your program, but then you don't want the information where your program behaves wrongly? ... Simply remove the flag again.Pasto
what is the point of using -fsanitize=address if you don't want his reportNadiya
@Nadiya Because OP is interested in memory overflows but not memory leaks?Cary
@Cary Indeed. I want to know of memory overflows, double free, use of temporary references after the object was destroyed, etc. Leaks don't matter as I run an app. for under 1 sec. and quit. It can leak as much as it wants. Unix way!Swellfish
C
39

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.

Cary answered 27/6, 2018 at 11:11 Comment(6)
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: linkSnelling
@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.