lldb leaks export MallocStackLogging=1
Mac自带的clang中没有包含
Sanitizer
, 需要安装llvmbrew install llvm
LeakSanitizer(LSan): 内存泄漏检查,可以单独使用
export ASAN_OPTIONS=detect_leaks=1
MemorySanitizer (MSan): 内存分配检查
in cmake -DCMAKE_BUILD_TYPE=ASAN -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -fsanitize=[sanitizer_name] [additional_options] [-g] [-OX]”)
Mac下C++内存检查指北(Valgrind VS Asan)
Memory check on macOS 12 Monterey?
Diagnosing Memory, Thread, and Crash Issues Early
google/sanitizers
Memory error checking in C and C++: Comparing Sanitizers and Valgrind