C++ 内存泄漏相关
ASAN
参考链接
- https://blog.csdn.net/wonengguwozai/article/details/129593186
- https://www.cnblogs.com/greatsql/p/16256926.html
小demo
// leak.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main(int argc, const char *argv[]) {char *s = (char*)malloc(100);strcpy(s, "Hello world!");printf("string is: %s\n", s);return 0;
}
~/Code/test$ gcc noleak.c -o noleak -fsanitize=address -g
~/Code/test$ ./leak
string is: Hello world!=================================================================
==1621572==ERROR: LeakSanitizer: detected memory leaks // 1)Direct leak of 100 byte(s) in 1 object(s) allocated from: // 2)#0 0x7f5b986bc808 in __interceptor_malloc ../../../../src/libsanitizer/ASAN/ASAN_malloc_linux.cc:144#1 0x562d866b5225 in main /home/chenbing/Code/test/leak.c:7#2 0x7f5b983e1082 in __libc_start_main ../csu/libc-start.c:308SUMMARY: AddressSanitizer: 100 byte(s) leaked in 1 allocation(s).