diff options
author | Sergey Matveev <earthdok@google.com> | 2015-04-24 16:53:15 +0000 |
---|---|---|
committer | Sergey Matveev <earthdok@google.com> | 2015-04-24 16:53:15 +0000 |
commit | 2513c38235538c1f5ac980cc79a46d5745a7c952 (patch) | |
tree | 7dc710426fb6dee315654c07d97abb1e909677f7 /test/lsan/TestCases | |
parent | 0e8cfc942e9a7907dc6d0396527c32429f352eb8 (diff) |
[lsan] Add an interface function for on-demand leak checking.
Summary:
Add an interface function which can be used to periodically trigger
leak detection in a long-running process.
NB: The meaning of the kIgnored tag has been changed to allow easy clean-up
between subsequent leak checks. Previously, this tag was applied to explicitly
ignored (i.e. with __lsan_disable() or __lsan_ignore_object()) chunks *and* any
chunks only reachable from those. With this change, it's only applied to
explicitly ignored chunks.
Reviewers: samsonov
Reviewed By: samsonov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D9159
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@235728 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/lsan/TestCases')
-rw-r--r-- | test/lsan/TestCases/recoverable_leak_check.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/lsan/TestCases/recoverable_leak_check.cc b/test/lsan/TestCases/recoverable_leak_check.cc new file mode 100644 index 000000000..0fe377f65 --- /dev/null +++ b/test/lsan/TestCases/recoverable_leak_check.cc @@ -0,0 +1,32 @@ +// Test for on-demand leak checking. +// RUN: LSAN_BASE="use_stacks=0:use_registers=0" +// RUN: %clangxx_lsan %s -o %t +// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t foo 2>&1 | FileCheck %s +// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sanitizer/lsan_interface.h> + +void *p; + +int main(int argc, char *argv[]) { + p = malloc(23); + + assert(__lsan_do_recoverable_leak_check() == 0); + + fprintf(stderr, "Test alloc: %p.\n", malloc(1337)); +// CHECK: Test alloc: + + assert(__lsan_do_recoverable_leak_check() == 1); +// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte + + // Test that we correctly reset chunk tags. + p = 0; + assert(__lsan_do_recoverable_leak_check() == 1); +// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1360 byte + + _exit(0); +} |