Mac OS:泄漏消毒剂 [英] Mac OS: Leaks Sanitizer
本文介绍了Mac OS:泄漏消毒剂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Mac OS X Sierra 10.13
Mac OS X Sierra 10.13
我照这里写的去做 https://clang.llvm.org/docs/LeakSanitizer.html
即创建了带有内存泄漏的小型应用程序
I.e. created the small application with memory leak
#include <stdlib.h>
void *p;
int main() {
p = malloc(7);
p = 0; // The memory is leaked here.
return 0;
}
然后构建它并运行以测试如何检测到内存泄漏:
Then build it and run to test how the memory leak is detected:
admins-Mac:test2 admin$ clang -fsanitize=address -g mleak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
==556==AddressSanitizer: detect_leaks is not supported on this platform.
Abort trap: 6
admins-Mac:test2 admin$
如何检测泄漏? 我需要在大型应用程序中使用它.
How I can detect the leak? I need to use it for my large application.
推荐答案
Apple提供的Clang/LLVM似乎没有-fsanitize=leak
支持.我通过在Homebrew上安装LLVM来修复它.关于要点
It seems that the Clang/LLVM shipped by Apple does not have -fsanitize=leak
support. I fixed it by installing LLVM on Homebrew. A more detailed fix is on gist
$ brew install llvm@8
# Overwritten default Clang
$ echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> .zshrc
$ source ~/.zshrc
$ which clang
/usr/local/opt/llvm/bin/clang
这篇关于Mac OS:泄漏消毒剂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文