31 lines · cpp
1// RUN: %clangxx_scudo %s -o %t2// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s3// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t mallocdel 2>&14// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s5// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t newfree 2>&16 7// Tests that type mismatches between allocation and deallocation functions are8// caught when the related option is set.9 10#include <assert.h>11#include <stdlib.h>12#include <string.h>13 14int main(int argc, char **argv) {15 assert(argc == 2);16 if (!strcmp(argv[1], "mallocdel")) {17 int *p = (int *)malloc(16);18 assert(p);19 delete p;20 }21 if (!strcmp(argv[1], "newfree")) {22 int *p = new int;23 assert(p);24 free((void *)p);25 }26 return 0;27}28 29// CHECK-dealloc: ERROR: allocation type mismatch when deallocating address30// CHECK-realloc: ERROR: allocation type mismatch when reallocating address31