What should I fix when Address Sanitizer says detect_leaks is not supported on this platform?

我与影子孤独终老i 提交于 2021-02-16 20:32:22

问题


I'm using Clang to compile my project, on x86_64 OS X(MacOS 10.15.5 Catalina).

I want to identify exactly from which file, which function, which line causes memory leaks. I am trying to use Address Sanitizer, specifically Leak Sanitizer.

Here are flags that I'm using when compiling:

-Wall -Wextra -flto -O3 -march=native -ffast-math -fsanitize=address

It successfully compiles. However, when I try to use run-time flag ASAN_OPTIONS=detect_leaks=1 in order to enable Leak Sanitizer, I see the following error:

==26454==AddressSanitizer: detect_leaks is not supported on this platform.
Abort trap: 6

What am I doing wrong? How could I fix this?

Or, is there another good alternative to a Valgrind? Valgrind doesn't work for me because 1)I'm using the MacOS Catalina, 2)My program runs with an infinite loop. If I'm right, Valgrind displays messages after exiting the program, so it won't work.

I would appreciate it if anyone could give me advice on this issue.


回答1:


What am I doing wrong?

Nothing. The issue is that your version of Clang does not support leak detection. However, it looks like the latest version does. See this answer and this recipe.

Valgrind displays messages after exiting the program, so it won't work.

You are somewhat correct: by default, Valgrind will perform leak analysis only at program exit.

There are two ways around this:

  1. Make your program exit at some well defined place in the execution, e.g. after performing N calculations, or drawing K frames, etc.

  2. Make your program perform VALGRIND_DO_LEAK_CHECK client request.

  3. If you want to perform the leak check only when certain conditions hold, and it's hard to detect whether these conditions are true from within the program, you could use GDB and the monitor command to ask Valgrind to perform leak check when desired.



来源:https://stackoverflow.com/questions/62315404/what-should-i-fix-when-address-sanitizer-says-detect-leaks-is-not-supported-on-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!