• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Test for on-demand leak checking.
2 // RUN: LSAN_BASE="use_stacks=0:use_registers=0"
3 // RUN: %clangxx_lsan %s -o %t
4 // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t foo 2>&1 | FileCheck %s
5 // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 2>&1 | FileCheck %s
6 
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <sanitizer/lsan_interface.h>
12 
13 void *p;
14 
main(int argc,char * argv[])15 int main(int argc, char *argv[]) {
16   p = malloc(23);
17 
18   assert(__lsan_do_recoverable_leak_check() == 0);
19 
20   fprintf(stderr, "Test alloc: %p.\n", malloc(1337));
21 // CHECK: Test alloc:
22 
23   assert(__lsan_do_recoverable_leak_check() == 1);
24 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte
25 
26   // Test that we correctly reset chunk tags.
27   p = 0;
28   assert(__lsan_do_recoverable_leak_check() == 1);
29 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1360 byte
30 
31   _exit(0);
32 }
33