• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main(int argc,char ** argv)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     if (!p)
20       return 1;
21     free(p);
22     free(p);
23   }
24   if (!strcmp(argv[1], "new")) {
25     int *p = new int;
26     if (!p)
27       return 1;
28     delete p;
29     delete p;
30   }
31   if (!strcmp(argv[1], "newarray")) {
32     int *p = new int[8];
33     if (!p)
34       return 1;
35     delete[] p;
36     delete[] p;
37   }
38   if (!strcmp(argv[1], "memalign")) {
39     void *p = nullptr;
40     posix_memalign(&p, 0x100, sizeof(int));
41     if (!p)
42       return 1;
43     free(p);
44     free(p);
45   }
46   return 0;
47 }
48 
49 // CHECK: ERROR: invalid chunk state when deallocating address
50