2013-05-29 10:12:37 +00:00
|
|
|
// Test that stacks of non-main threads are included in the root set.
|
2017-01-23 08:45:17 +00:00
|
|
|
// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0"
|
2013-05-29 10:12:37 +00:00
|
|
|
// RUN: %clangxx_lsan -pthread %s -o %t
|
2014-04-30 21:34:17 +00:00
|
|
|
// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s
|
|
|
|
// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %run %t 2>&1
|
|
|
|
// RUN: LSAN_OPTIONS="" %run %t 2>&1
|
2013-05-29 10:12:37 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <pthread.h>
|
2014-07-21 13:01:06 +00:00
|
|
|
#include <sched.h>
|
2013-05-29 10:12:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-11-14 11:40:56 +00:00
|
|
|
#include "sanitizer_common/print_address.h"
|
2013-05-29 10:12:37 +00:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
void *stacks_thread_func(void *arg) {
|
|
|
|
int *sync = reinterpret_cast<int *>(arg);
|
|
|
|
void *p = malloc(1337);
|
2016-10-20 12:25:57 +00:00
|
|
|
print_address("Test alloc: ", 1, p);
|
2013-05-29 10:12:37 +00:00
|
|
|
fflush(stderr);
|
|
|
|
__sync_fetch_and_xor(sync, 1);
|
|
|
|
while (true)
|
2014-07-21 13:01:06 +00:00
|
|
|
sched_yield();
|
2013-05-29 10:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int sync = 0;
|
|
|
|
pthread_t thread_id;
|
|
|
|
int res = pthread_create(&thread_id, 0, stacks_thread_func, &sync);
|
|
|
|
assert(res == 0);
|
|
|
|
while (!__sync_fetch_and_xor(&sync, 0))
|
2014-07-21 13:01:06 +00:00
|
|
|
sched_yield();
|
2013-05-29 10:12:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-10-20 12:25:57 +00:00
|
|
|
// CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
|
2013-06-19 14:04:11 +00:00
|
|
|
// CHECK: LeakSanitizer: detected memory leaks
|
2013-12-24 12:03:02 +00:00
|
|
|
// CHECK: [[ADDR]] (1337 bytes)
|
2013-11-01 17:02:14 +00:00
|
|
|
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
|