34 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=text -verify %s2 3// expected-no-diagnostics4 5typedef void *CFTypeRef;6typedef struct _CFURLCacheRef *CFURLCacheRef;7 8CFTypeRef CustomCFRetain(CFTypeRef);9void invalidate(void *);10struct S1 {11 CFTypeRef s;12 CFTypeRef returnFieldAtPlus0() {13 return s;14 }15};16struct S2 {17 S1 *s1;18};19void foo(S1 *s1) {20 invalidate(s1);21 S2 s2;22 s2.s1 = s1;23 CustomCFRetain(s1->returnFieldAtPlus0());24 25 // Definitely no leak end-of-path note here. The retained pointer26 // is still accessible through s1 and s2.27 ((void) 0); // no-warning28 29 // FIXME: Ideally we need to warn after this invalidate(). The per-function30 // retain-release contract is violated: the programmer should release31 // the symbol after it was retained, within the same function.32 invalidate(&s2);33}34