1 // We can't unwind stack if we're running coroutines on heap-allocated 2 // memory. Make sure we don't report these leaks. 3 4 // RUN: %clangxx_lsan %s -o %t 5 // RUN: %env_lsan_opts= %run %t 2>&1 6 // RUN: %env_lsan_opts= not %run %t foo 2>&1 | FileCheck %s 7 // UNSUPPORTED: arm,powerpc64 8 9 #include "sanitizer_common/sanitizer_ucontext.h" 10 #include <stdio.h> 11 #include <unistd.h> 12 13 const int kStackSize = 1 << 20; 14 15 void Child() { 16 int child_stack; 17 printf("Child: %p\n", &child_stack); 18 int *leaked = new int[666]; 19 } 20 21 int main(int argc, char *argv[]) { 22 char stack_memory[kStackSize + 1] __attribute__((aligned(16))); 23 char *heap_memory = new char[kStackSize + 1]; 24 char *child_stack = (argc > 1) ? stack_memory : heap_memory; 25 26 printf("Child stack: %p\n", child_stack); 27 ucontext_t orig_context; 28 ucontext_t child_context; 29 getcontext(&child_context); 30 child_context.uc_stack.ss_sp = child_stack; 31 child_context.uc_stack.ss_size = kStackSize / 2; 32 child_context.uc_link = &orig_context; 33 makecontext(&child_context, Child, 0); 34 if (swapcontext(&orig_context, &child_context) < 0) { 35 perror("swapcontext"); 36 return 1; 37 } 38 39 delete[] heap_memory; 40 return 0; 41 } 42 43 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 2664 byte(s) leaked in 1 allocation(s) 44