[lldb] Fix TestLoadUnload.py (#117416)
[llvm-project.git] / compiler-rt / test / scudo / double-free.cpp
blobce6ef5119ec471ff5468f48e1258fd93f40c87a7
1 // RUN: %clangxx_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
6 // Tests double-free error on pointers allocated with different allocation
7 // functions.
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <string.h>
13 int main(int argc, char **argv) {
14 assert(argc == 2);
15 if (!strcmp(argv[1], "malloc")) {
16 void *p = malloc(sizeof(int));
17 assert(p);
18 free(p);
19 free(p);
21 if (!strcmp(argv[1], "new")) {
22 int *p = new int;
23 assert(p);
24 delete p;
25 delete p;
27 if (!strcmp(argv[1], "newarray")) {
28 int *p = new int[8];
29 assert(p);
30 delete[] p;
31 delete[] p;
33 return 0;
36 // CHECK: ERROR: invalid chunk state