Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / tools / clang-tidy / test / clang-analyzer-unix.Malloc.cpp
bloba08422b336f3132ccc49245cac09c34ccbe71b94
1 // https://clang-analyzer.llvm.org/available_checks.html
3 #include "structures.h"
5 void test_malloc()
7 int *p = (int*) malloc(1);
8 free(p);
9 free(p); // warning: attempt to free released memory
12 void test_use_after_free()
14 int *p = (int*) malloc(sizeof(int));
15 free(p);
16 *p = 1; // warning: use after free
19 void test_leak()
21 int *p = (int*) malloc(1);
22 if (p)
23 return; // warning: memory is never released
26 void test_free_local()
28 int a[] = { 1 };
29 free(a); // warning: argument is not allocated by malloc
32 void test_free_offset()
34 int *p = (int*) malloc(sizeof(char));
35 p = p - 1;
36 free(p); // warning: argument to free() is offset by -4 bytes