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