You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
650 B
30 lines
650 B
// REQUIRES: gwp_asan
|
|
// RUN: %clang_gwp_asan %s -g -o %t
|
|
// RUN: %expect_crash %t 2>&1 | FileCheck %s
|
|
|
|
#include <stdlib.h>
|
|
|
|
__attribute__((noinline)) void *allocate_mem() { return malloc(1); }
|
|
|
|
__attribute__((noinline)) void free_mem(void *ptr) { free(ptr); }
|
|
|
|
__attribute__((noinline)) void touch_mem(void *ptr) {
|
|
volatile char sink = *((volatile char *)ptr);
|
|
}
|
|
|
|
// CHECK: Use After Free
|
|
// CHECK: touch_mem
|
|
// CHECK: was deallocated
|
|
// CHECK: free_mem
|
|
// CHECK: was allocated
|
|
// CHECK: allocate_mem
|
|
|
|
int main() {
|
|
for (unsigned i = 0; i < 0x10000; ++i) {
|
|
void *ptr = allocate_mem();
|
|
free_mem(ptr);
|
|
touch_mem(ptr);
|
|
}
|
|
return 0;
|
|
}
|