1 // Test that statically allocated thread-specific storage is included in the root set. 2 // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" 3 // RUN: %clangxx_lsan %s -o %t 4 // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s 5 // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %run %t 2>&1 6 // RUN: LSAN_OPTIONS="" %run %t 2>&1 7 8 #include <assert.h> 9 #include <pthread.h> 10 #include <stdio.h> 11 #include <stdlib.h> 12 13 // From glibc: this many keys are stored in the thread descriptor directly. 14 const unsigned PTHREAD_KEY_2NDLEVEL_SIZE = 32; 15 main()16int main() { 17 pthread_key_t key; 18 int res; 19 res = pthread_key_create(&key, NULL); 20 assert(res == 0); 21 assert(key < PTHREAD_KEY_2NDLEVEL_SIZE); 22 void *p = malloc(1337); 23 res = pthread_setspecific(key, p); 24 assert(res == 0); 25 fprintf(stderr, "Test alloc: %p.\n", p); 26 return 0; 27 } 28 // CHECK: Test alloc: [[ADDR:.*]]. 29 // CHECK: LeakSanitizer: detected memory leaks 30 // CHECK: [[ADDR]] (1337 bytes) 31 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 32