ASAN

作者: mjzxcvbnm | 来源:发表于2022-07-20 21:06 被阅读0次

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 <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$

相关文章

网友评论

      本文标题:ASAN

      本文链接:https://www.haomeiwen.com/subject/rxeyirtx.html