1 // Test for __lsan_ignore_object(). 2 // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0:verbosity=3" 3 // RUN: %clangxx_lsan %s -o %t 4 // RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 9 #include "sanitizer/lsan_interface.h" 10 11 int main() { 12 { 13 // The first malloc call can cause an allocation in libdl. Ignore it here so 14 // it doesn't show up in our output. 15 __lsan::ScopedDisabler d; 16 malloc(1); 17 } 18 // Explicitly ignored object. 19 void **p = new void *; 20 // Transitively ignored object. 21 *p = malloc(666); 22 // Non-ignored object. 23 volatile void *q = malloc(1337); 24 fprintf(stderr, "Test alloc: %p.\n", p); 25 __lsan_ignore_object(p); 26 return 0; 27 } 28 // CHECK: Test alloc: [[ADDR:.*]]. 29 // CHECK: ignoring heap object at [[ADDR]] 30 // CHECK: SUMMARY: LeakSanitizer: 1337 byte(s) leaked in 1 allocation(s) 31