Skip to content

Commit ca8dfa9

Browse files
committed
add example for mismatched deallocation class in documentation
1 parent 0392ef9 commit ca8dfa9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ void test() {
66

77
// C, C++
88
void __attribute((ownership_returns(malloc))) *user_malloc(size_t);
9+
void __attribute((ownership_takes(malloc, 1))) *user_free(void *);
10+
11+
void __attribute((ownership_returns(malloc1))) *user_malloc1(size_t);
12+
void __attribute((ownership_takes(malloc1, 1))) *user_free1(void *);
913

1014
void test() {
1115
int *p = (int *)user_malloc(sizeof(int));
@@ -24,6 +28,12 @@ void test() {
2428
realloc(p, sizeof(long)); // warn
2529
}
2630

31+
// C, C++
32+
void test() {
33+
int *p = user_malloc(10);
34+
user_free1(p); // warn
35+
}
36+
2737
// C, C++
2838
template <typename T>
2939
struct SimpleSmartPointer {

0 commit comments

Comments
 (0)