xref: /llvm-project/clang/test/Analysis/malloc-bodyfarms.c (revision e0e174845b08b36a3888f47f6b06e496f75cf847)
1 // RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s
2 
3 typedef __typeof(sizeof(int)) size_t;
4 void *calloc(size_t, size_t);
5 
6 typedef struct dispatch_queue_s *dispatch_queue_t;
7 typedef void (^dispatch_block_t)(void);
8 void dispatch_sync(dispatch_queue_t, dispatch_block_t);
9 
test_no_state_change_in_body_farm(dispatch_queue_t queue)10 void test_no_state_change_in_body_farm(dispatch_queue_t queue) {
11   dispatch_sync(queue, ^{}); // no-crash
12   calloc(1, 1);
13 } // expected-warning{{Potential memory leak}}
14 
test_no_state_change_in_body_farm_2(dispatch_queue_t queue)15 void test_no_state_change_in_body_farm_2(dispatch_queue_t queue) {
16   void *p = calloc(1, 1);
17   dispatch_sync(queue, ^{}); // no-crash
18   p = 0;
19 } // expected-warning{{Potential leak of memory pointed to by 'p'}}
20