Detecting Memory Leak using GCC
( without Valgrind)
#include
int main()
{
int *prt =(int*) malloc(sizeof(int));;
return 0;
}
08:46:32alok@~$ gcc memory_leak.c
08:46:51alok@~$ ./a.out
08:46:52alok@~$ gcc -fsanitize=address -g memory_leak.c
08:46:59alok@~$ ./a.out
====================================================
==4221==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4 byte(s) in 1 object(s) allocated from:
#0 0x7fe31f218acb in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/liblsan.so.0+0xeacb)
#1 0x558bd3ad271b in main /home/alok/memory_leak.c:4
#2 0x7fe31ee3ab96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
SUMMARY: LeakSanitizer: 4 byte(s) leaked in 1 allocation(s).
No comments:
Post a Comment