1 | void f(int *p); |
2 | |
3 | void testUseMiddleArgAfterDelete(int *p) { |
4 | delete p; |
5 | f(p); // warn: use after free |
6 | } |
7 | |
8 | class SomeClass { |
9 | public: |
10 | void f(); |
11 | }; |
12 | |
13 | void test() { |
14 | SomeClass *c = new SomeClass; |
15 | delete c; |
16 | c->f(); // warn: use after free |
17 | } |
18 | |
19 | void test() { |
20 | int *p = (int *)__builtin_alloca(sizeof(int)); |
21 | delete p; // warn: deleting memory allocated by alloca |
22 | } |
23 | |
24 | void test() { |
25 | int *p = new int; |
26 | delete p; |
27 | delete p; // warn: attempt to free released |
28 | } |
29 | |
30 | void test() { |
31 | int i; |
32 | delete &i; // warn: delete address of local |
33 | } |
34 | |
35 | void 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 | |