28 lines · cpp
1// Test that SIGSEGV during leak checking does not crash the process.2// RUN: %clangxx_lsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s3// UNSUPPORTED: ppc4#include <sanitizer/lsan_interface.h>5#include <stdio.h>6#include <stdlib.h>7#include <sys/mman.h>8#include <unistd.h>9 10char data[10 * 1024 * 1024];11 12int main() {13 long pagesize_mask = sysconf(_SC_PAGESIZE) - 1;14 void *p = malloc(10 * 1024 * 1024);15 // surprise-surprise!16 mprotect((void *)(((unsigned long)p + pagesize_mask) & ~pagesize_mask),17 16 * 1024, PROT_NONE);18 mprotect((void *)(((unsigned long)data + pagesize_mask) & ~pagesize_mask),19 16 * 1024, PROT_NONE);20 __lsan_do_leak_check();21 fprintf(stderr, "DONE\n");22}23 24// CHECK: Tracer caught signal 1125// CHECK: LeakSanitizer has encountered a fatal error26// CHECK: HINT: For debugging, try setting {{.*}} LSAN_OPTIONS27// CHECK-NOT: DONE28