1 // RUN: %clang_scudo %s -o %t
2 // RUN: not %run %t malloc   2>&1 | FileCheck %s
3 // RUN: not %run %t new      2>&1 | FileCheck %s
4 // RUN: not %run %t newarray 2>&1 | FileCheck %s
5 // RUN: not %run %t memalign 2>&1 | FileCheck %s
6 
7 // Tests double-free error on pointers allocated with different allocation
8 // functions.
9 
10 #include <assert.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 int main(int argc, char **argv)
15 {
16   assert(argc == 2);
17   if (!strcmp(argv[1], "malloc")) {
18     void *p = malloc(sizeof(int));
19     assert(p);
20     free(p);
21     free(p);
22   }
23   if (!strcmp(argv[1], "new")) {
24     int *p = new int;
25     assert(p);
26     delete p;
27     delete p;
28   }
29   if (!strcmp(argv[1], "newarray")) {
30     int *p = new int[8];
31     assert(p);
32     delete[] p;
33     delete[] p;
34   }
35   if (!strcmp(argv[1], "memalign")) {
36     void *p = nullptr;
37     posix_memalign(&p, 0x100, sizeof(int));
38     assert(p);
39     free(p);
40     free(p);
41   }
42   return 0;
43 }
44 
45 // CHECK: ERROR: invalid chunk state
46