-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hi!
This is a simple test demonstrating false-negative memory leak detection when two functions stack frames overlay; here the first function allocates memory and stores pointer in the stack, and the second function invokes lsan to detect memory leak
$ uname -a
Linux machine_name 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u4 (2015-09-19) x86_64 GNU/Linux
$ clang --version | head -1
clang version 5.0.1 (tags/RELEASE_501/final)
$ cat t.c
#include <sanitizer/lsan_interface.h>
#include <stdlib.h>
#include <assert.h>
#define NOINLINE __attribute__((noinline))
NOINLINE
void foo( size_t size )
{
volatile char * a[128];
a[0] = (volatile char *)malloc( size );
assert( a[0] );
}
NOINLINE
void bar( void )
{
#ifdef ENABLE_LSAN_FALSE_NEGATIVE
volatile char * a[128];
#endif
__lsan_do_leak_check();
}
int main( int argc, char ** argv )
{
foo( argc );
bar();
return 0;
}
$ clang t.c -fsanitize=leak -DENABLE_LSAN_FALSE_NEGATIVE && ./a.out
$ echo $?
0
if we unset the macro ENABLE_LSAN_FALSE_NEGATIVE then lsan will detect memory leak as expected
$ clang t.c -fsanitize=leak && ./a.out
=================================================================
==4778==ERROR: LeakSanitizer: detected memory leaksDirect leak of 1 byte(s) in 1 object(s) allocated from
#0 0x4097c7 in __interceptor_malloc ...
...