Skip to content

Commit 12292c8

Browse files
committed
[NFC][Asan] Add another lsan test
1 parent 83286a1 commit 12292c8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Test for LeakSanitizer+AddressSanitizer of different sizes.
2+
// REQUIRES: leak-detection
3+
//
4+
// RUN: %clangxx_asan -O0 %s -o %t
5+
// RUN: not %run %t 0 2>&1 | FileCheck %s
6+
// RUN: not %run %t 1 2>&1 | FileCheck %s
7+
// RUN: not %run %t 1000 2>&1 | FileCheck %s
8+
// RUN: not %run %t 1000000 2>&1 | FileCheck %s
9+
// RUN: not %run %t 10000000 2>&1 | FileCheck %s
10+
11+
#include <cstdlib>
12+
#include <stdio.h>
13+
#include <thread>
14+
int *t;
15+
16+
__attribute__((noopt)) void leak(int n) {
17+
// Repeat few times to make sure that at least one pointer is
18+
// not somewhere on the stack.
19+
for (int i = 0; i < 10; ++i) {
20+
t = new int[n];
21+
printf("t: %p\n", t);
22+
t = 0;
23+
}
24+
}
25+
26+
int main(int argc, char **argv) {
27+
leak(atoi(argv[1]));
28+
}
29+
// CHECK: LeakSanitizer: detected memory leaks

0 commit comments

Comments
 (0)