1
2
3void test() {
4 unsigned int *ptr = 0;
5 UInt32 length;
6
7 SecKeychainItemFreeContent(ptr, &length);
8 // warn: trying to free data which has not been allocated
9}
10
11void test() {
12 unsigned int *ptr = 0;
13 UInt32 *length = 0;
14 void *outData;
15
16 OSStatus st =
17 SecKeychainItemCopyContent(2, ptr, ptr, length, outData);
18 // warn: data is not released
19}
20
21void test() {
22 unsigned int *ptr = 0;
23 UInt32 *length = 0;
24 void *outData;
25
26 OSStatus st =
27 SecKeychainItemCopyContent(2, ptr, ptr, length, &outData);
28
29 SecKeychainItemFreeContent(ptr, outData);
30 // warn: only call free if a non-NULL buffer was returned
31}
32
33void test() {
34 unsigned int *ptr = 0;
35 UInt32 *length = 0;
36 void *outData;
37
38 OSStatus st =
39 SecKeychainItemCopyContent(2, ptr, ptr, length, &outData);
40
41 st = SecKeychainItemCopyContent(2, ptr, ptr, length, &outData);
42 // warn: release data before another call to the allocator
43
44 if (st == noErr)
45 SecKeychainItemFreeContent(ptr, outData);
46}
47
48void test() {
49 SecKeychainItemRef itemRef = 0;
50 SecKeychainAttributeInfo *info = 0;
51 SecItemClass *itemClass = 0;
52 SecKeychainAttributeList *attrList = 0;
53 UInt32 *length = 0;
54 void *outData = 0;
55
56 OSStatus st =
57 SecKeychainItemCopyAttributesAndData(itemRef, info,
58 itemClass, &attrList,
59 length, &outData);
60
61 SecKeychainItemFreeContent(attrList, outData);
62 // warn: deallocator doesn't match the allocator
63}
64
65

source code of clang/docs/analyzer/checkers/seckeychainapi_example.m