1 | // Test for on-demand leak checking. |
2 | // RUN: %clangxx_lsan %s -o %t |
3 | // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 %run %t foo 2>&1 | FileCheck %s |
4 | // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 %run %t 2>&1 | FileCheck %s |
5 | |
6 | // UNSUPPORTED: darwin |
7 | |
8 | // FIXME: Investigate. |
9 | // XFAIL: internal_symbolizer && lsan-standalone && i386-linux |
10 | |
11 | #include <assert.h> |
12 | #include <stdio.h> |
13 | #include <stdlib.h> |
14 | #include <unistd.h> |
15 | #include <sanitizer/lsan_interface.h> |
16 | |
17 | void *p; |
18 | |
19 | int main(int argc, char *argv[]) { |
20 | p = malloc(size: 23); |
21 | |
22 | assert(__lsan_do_recoverable_leak_check() == 0); |
23 | |
24 | fprintf(stderr, format: "Test alloc: %p.\n" , malloc(size: 1337)); |
25 | // CHECK: Test alloc: |
26 | |
27 | assert(__lsan_do_recoverable_leak_check() == 1); |
28 | // CHECK: SUMMARY: {{.*}}Sanitizer: 1337 byte |
29 | |
30 | // Test that we correctly reset chunk tags. |
31 | p = 0; |
32 | assert(__lsan_do_recoverable_leak_check() == 1); |
33 | // CHECK: SUMMARY: {{.*}}Sanitizer: 1360 byte |
34 | |
35 | _exit(status: 0); |
36 | } |
37 | |