Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22453

Why LSan (with gcc) doesn't find memory leaks which are allocated by mmap?

$
0
0

I tested it with below code

// main.c#include <sys/mman.h>#include <string.h>#include <stdlib.h>int main() {    int* ptr1 = (int*)malloc(1);    int* ptr2 = (int*)mmap(0, 4096*10, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0);}

I build like below and run it
And as the result shows LSan only found a leak with malloc
Is there any option that force it to find leaks with mmap or LSan is just designed to do so?

$ gcc -fsanitize=address -O0 main.cpp$ ASAN_OPTIONS=detect_leaks=1 ./a.out===================================================================14654==ERROR: LeakSanitizer: detected memory leaksDirect leak of 1 byte(s) in 1 object(s) allocated from:    #0 0x7fc1054f0b50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)    #1 0x55c984e2283b in main (/home/work/a.out+0x83b)    #2 0x7fc105042b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)SUMMARY: AddressSanitizer: 1 byte(s) leaked in 1 allocation(s).

Viewing all articles
Browse latest Browse all 22453

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>