1 | |
2 | void test() { |
3 | int *p = malloc(1); |
4 | free(p); |
5 | free(p); // warn: attempt to free released memory |
6 | } |
7 | |
8 | void test() { |
9 | int *p = malloc(sizeof(int)); |
10 | free(p); |
11 | *p = 1; // warn: use after free |
12 | } |
13 | |
14 | void test() { |
15 | int *p = malloc(1); |
16 | if (p) |
17 | return; // warn: memory is never released |
18 | } |
19 | |
20 | void test() { |
21 | int a[] = { 1 }; |
22 | free(a); // warn: argument is not allocated by malloc |
23 | } |
24 | |
25 | void test() { |
26 | int *p = malloc(sizeof(char)); |
27 | p = p - 1; |
28 | free(p); // warn: argument to free() is offset by -4 bytes |
29 | } |
30 | |
31 | |