20 lines · c
1// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s2 3typedef __typeof(sizeof(int)) size_t;4void *calloc(size_t, size_t);5 6typedef struct dispatch_queue_s *dispatch_queue_t;7typedef void (^dispatch_block_t)(void);8void dispatch_sync(dispatch_queue_t, dispatch_block_t);9 10void test_no_state_change_in_body_farm(dispatch_queue_t queue) {11 dispatch_sync(queue, ^{}); // no-crash12 calloc(1, 1);13} // expected-warning{{Potential memory leak}}14 15void test_no_state_change_in_body_farm_2(dispatch_queue_t queue) {16 void *p = calloc(1, 1);17 dispatch_sync(queue, ^{}); // no-crash18 p = 0;19} // expected-warning{{Potential leak of memory pointed to by 'p'}}20