blob: 54cdafc86ee6772ba90a97799bfb764d115f1f84 [file] [log] [blame]
Kostya Serebryany712fc982016-06-07 01:20:26 +00001// RUN: %clang_scudo %s -o %t
2// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck %s
3// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t mallocdel 2>&1
4// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck %s
5// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t newfree 2>&1
6// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t memaligndel 2>&1 | FileCheck %s
7// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t memaligndel 2>&1
8
9// Tests that type mismatches between allocation and deallocation functions are
10// caught when the related option is set.
11
12#include <assert.h>
13#include <stdlib.h>
14#include <string.h>
15#include <malloc.h>
16
17int main(int argc, char **argv)
18{
19 assert(argc == 2);
20 if (!strcmp(argv[1], "mallocdel")) {
21 int *p = (int *)malloc(16);
22 if (!p)
23 return 1;
24 delete p;
25 }
26 if (!strcmp(argv[1], "newfree")) {
27 int *p = new int;
28 if (!p)
29 return 1;
30 free((void *)p);
31 }
32 if (!strcmp(argv[1], "memaligndel")) {
Kostya Kortchinsky1148dc52016-11-30 17:32:20 +000033 int *p = (int *)memalign(16, 16);
Kostya Serebryany712fc982016-06-07 01:20:26 +000034 if (!p)
35 return 1;
36 delete p;
37 }
38 return 0;
39}
40
41// CHECK: ERROR: allocation type mismatch on address