ASAN_OPTIONS
# halt_on_error=0; 檢測內(nèi)存錯誤后繼續(xù)運行
# detect_leaks=1;使能內(nèi)存泄露檢測
# malloc_context_size=15 : 內(nèi)存錯誤發(fā)生時够坐,顯示的調(diào)用棧層數(shù)為15
# log_path=/home/jing/asan.log : 內(nèi)存檢查問題日志存放文件路徑
export ASAN_OPTIONS=halt_on_error=0:detect_leaks=1:malloc_context_size=15:log_path=/home/jing/asan.log
memory leak
cat memory_leak.cpp
#include <stdlib.h>
#include <stdint.h>
int main()
{
uint8_t *p = (uint8_t *)malloc(10 * sizeof(uint8_t));
return 0;
}
jing@jing-Satellite-L510:~/asan$ g++ -fsanitize=address -g memory_leak.cpp
jing@jing-Satellite-L510:~/asan$ ./a.out
=================================================================
==3912==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 10 byte(s) in 1 object(s) allocated from:
#0 0x7f8772792808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
#1 0x55c4df3e419e in main /home/jing/asan/memory_leak.cpp:6
#2 0x7f877216b082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: 10 byte(s) leaked in 1 allocation(s).
jing@jing-Satellite-L510:~/asan$