1 // REQUIRES: gwp_asan 2 // RUN: %clang_gwp_asan %s -g -o %t 3 // RUN: %expect_crash %t 2>&1 | FileCheck %s 4 5 #include <stdlib.h> 6 allocate_mem()7__attribute__((noinline)) void *allocate_mem() { return malloc(1); } 8 free_mem(void * ptr)9__attribute__((noinline)) void free_mem(void *ptr) { free(ptr); } 10 touch_mem(void * ptr)11__attribute__((noinline)) void touch_mem(void *ptr) { 12 volatile char sink = *((volatile char *)ptr); 13 } 14 15 // CHECK: Use After Free 16 // CHECK: touch_mem 17 // CHECK: was deallocated 18 // CHECK: free_mem 19 // CHECK: was allocated 20 // CHECK: allocate_mem 21 main()22int main() { 23 for (unsigned i = 0; i < 0x10000; ++i) { 24 void *ptr = allocate_mem(); 25 free_mem(ptr); 26 touch_mem(ptr); 27 } 28 return 0; 29 } 30