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