1void f(int *p);
2
3void testUseMiddleArgAfterDelete(int *p) {
4 delete p;
5 f(p); // warn: use after free
6}
7
8class SomeClass {
9public:
10 void f();
11};
12
13void test() {
14 SomeClass *c = new SomeClass;
15 delete c;
16 c->f(); // warn: use after free
17}
18
19void test() {
20 int *p = (int *)__builtin_alloca(sizeof(int));
21 delete p; // warn: deleting memory allocated by alloca
22}
23
24void test() {
25 int *p = new int;
26 delete p;
27 delete p; // warn: attempt to free released
28}
29
30void test() {
31 int i;
32 delete &i; // warn: delete address of local
33}
34
35void test() {
36 int *p = new int[1];
37 delete[] (++p);
38 // warn: argument to 'delete[]' is offset by 4 bytes
39 // from the start of memory allocated by 'new[]'
40}
41
42

source code of clang/docs/analyzer/checkers/newdelete_example.cpp