ASAN

ASAN_OPTIONS

# halt_on_error=0; 检测内存错误后继续运行
# detect_leaks=1;使能内存泄露检测
# malloc_context_size=15  : 内存错误发生时,显示的调用栈层数为15
# log_path=/home/jing/asan.log : 内存检查问题日志存放文件路径
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 
#include 

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$

你可能感兴趣的:(ASAN)