1 // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 3 #include <stdlib.h> 4 #include <string.h> 5 int main(int argc, char **argv) { 6 char *x = (char*)malloc(10 * sizeof(char)); 7 memset(x, 0, 10); 8 int res = x[argc]; 9 free(x); 10 free(x + argc - 1); // BOOM 11 // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0 12 // CHECK: double-free.cc:[[@LINE-2]] 13 // CHECK: freed by thread T0 here: 14 // CHECK: double-free.cc:[[@LINE-5]] 15 // CHECK: allocated by thread T0 here: 16 // CHECK: double-free.cc:[[@LINE-10]] 17 return res; 18 } 19