cfref_PR2519.c revision 0964a06d5cc1dc36ac5f8c89ba47ec0a47c08bb1
1// RUN: clang -analyze -checker-cfref --analyzer-store-basic -verify %s && 2// RUN: clang -analyze -checker-cfref --analyzer-store-region -verify %s 3 4typedef unsigned char Boolean; 5typedef signed long CFIndex; 6typedef const void * CFTypeRef; 7typedef const struct __CFString * CFStringRef; 8typedef const struct __CFAllocator * CFAllocatorRef; 9extern const CFAllocatorRef kCFAllocatorDefault; 10typedef struct {} CFAllocatorContext; 11extern void CFRelease(CFTypeRef cf); 12typedef struct {} 13CFDictionaryKeyCallBacks; 14extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks; 15typedef struct {} 16CFDictionaryValueCallBacks; 17extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks; 18typedef const struct __CFDictionary * CFDictionaryRef; 19extern CFDictionaryRef CFDictionaryCreate(CFAllocatorRef allocator, const void **keys, const void **values, CFIndex numValues, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks); 20enum { kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 }; 21typedef CFIndex CFNumberType; 22typedef const struct __CFNumber * CFNumberRef; 23extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr); 24typedef struct __CFNotificationCenter * CFNotificationCenterRef; 25extern CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void); 26extern void CFNotificationCenterPostNotification(CFNotificationCenterRef center, CFStringRef name, const void *object, CFDictionaryRef userInfo, Boolean deliverImmediately); 27 28// This test case was reported in PR2519 as a false positive (_value was 29// reported as being leaked). 30 31int main(int argc, char **argv) { 32 CFStringRef _key = ((CFStringRef) __builtin___CFStringMakeConstantString ("" "Process identifier" "")); 33 int pid = 42; 34 35 CFNumberRef _value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid); 36 CFDictionaryRef userInfo = CFDictionaryCreate(kCFAllocatorDefault, (const void **)&_key, (const void **)&_value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 37 CFRelease(_value); // no-warning 38 CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), 39 ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlPreferencesChanged" "")), 40 ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlUserDefaults" "")), 41 userInfo, 0); 42 CFRelease(userInfo); // no-warning 43 44 return 0; 45} 46 47