1 // RUN: %clang_scudo %s -o %t 2 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck %s 3 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t mallocdel 2>&1 4 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck %s 5 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t newfree 2>&1 6 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t memaligndel 2>&1 | FileCheck %s 7 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t memaligndel 2>&1 8 9 // Tests that type mismatches between allocation and deallocation functions are 10 // caught when the related option is set. 11 12 #include <assert.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <malloc.h> 16 17 int main(int argc, char **argv) 18 { 19 assert(argc == 2); 20 if (!strcmp(argv[1], "mallocdel")) { 21 int *p = (int *)malloc(16); 22 if (!p) 23 return 1; 24 delete p; 25 } 26 if (!strcmp(argv[1], "newfree")) { 27 int *p = new int; 28 if (!p) 29 return 1; 30 free((void *)p); 31 } 32 if (!strcmp(argv[1], "memaligndel")) { 33 int *p = (int *)memalign(0x10, 0x10); 34 if (!p) 35 return 1; 36 delete p; 37 } 38 return 0; 39 } 40 41 // CHECK: ERROR: allocation type mismatch on address 42