You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// expected-warning@-1{{Incorrect use of RetainPtr constructor. The argument is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
// expected-warning@-1{{Incorrect use of adoptCF. The argument is +0 and results in an use-after-free [alpha.webkit.RetainPtrCtorAdoptChecker]}}
30
+
// expected-warning@-1{{Incorrect use of adoptCF. The argument is +0 and results in an use-after-free when ARC is disabled [alpha.webkit.RetainPtrCtorAdoptChecker]}}
// expected-warning@-1{{Incorrect use of RetainPtr constructor. The argument is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
33
33
CFCopyArray(cf1);
34
34
// expected-warning@-1{{The return value is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
35
35
}
36
36
37
+
voidbasic_correct_arc() {
38
+
auto *obj = [[SomeObj alloc] init];
39
+
[obj doWork];
40
+
}
41
+
42
+
@implementationSomeObj {
43
+
NSNumber *_number;
44
+
SomeObj *_next;
45
+
SomeObj *_other;
46
+
}
47
+
48
+
- (instancetype)_init {
49
+
self = [superinit];
50
+
_number = nil;
51
+
_next = nil;
52
+
_other = nil;
53
+
return self;
54
+
}
55
+
56
+
- (SomeObj *)mutableCopy {
57
+
auto *copy = [[SomeObj alloc] init];
58
+
[copy setValue:_number];
59
+
[copy setNext:_next];
60
+
[copy setOther:_other];
61
+
return copy;
62
+
}
63
+
64
+
- (SomeObj *)copyWithValue:(int)value {
65
+
auto *copy = [[SomeObj alloc] init];
66
+
[copy setValue:_number];
67
+
[copy setNext:_next];
68
+
[copy setOther:_other];
69
+
return copy;
70
+
}
71
+
72
+
- (void)doWork {
73
+
_number = [[NSNumberalloc] initWithInt:5];
74
+
}
75
+
76
+
- (SomeObj *)other {
77
+
return _other;
78
+
}
79
+
80
+
- (void)setOther:(SomeObj *)obj {
81
+
_other = obj;
82
+
}
83
+
84
+
- (SomeObj *)next {
85
+
return _next;
86
+
}
87
+
88
+
- (void)setNext:(SomeObj *)obj {
89
+
_next = obj;
90
+
}
91
+
92
+
- (int)value {
93
+
return [_number intValue];
94
+
}
95
+
96
+
- (void)setValue:(NSNumber *)value {
97
+
_number = value;
98
+
}
99
+
100
+
@end;
101
+
37
102
RetainPtr<CVPixelBufferRef> cf_out_argument() {
38
103
auto surface = adoptCF(IOSurfaceCreate(nullptr));
39
104
CVPixelBufferRef rawBuffer = nullptr;
@@ -60,7 +125,46 @@ void cast_retainptr() {
60
125
RetainPtr<CFArrayRef> v = static_cast<CFArrayRef>(baz);
61
126
}
62
127
63
-
SomeObj* allocSomeObj();
128
+
CFTypeRef CopyWrapper() {
129
+
returnCopyValueForSomething();
130
+
}
131
+
132
+
CFTypeRef LeakWrapper() {
133
+
returnCopyValueForSomething();
134
+
// expected-warning@-1{{The return value is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
auto cf2 = adoptCF(SecTaskCreateFromSelf(kCFAllocatorDefault));
258
+
auto cf3 = adoptCF(checked_cf_cast<CFArrayRef>(CFCopyArray(cf1)));
259
+
}
260
+
261
+
-(void)basic_wrong {
262
+
RetainPtr<SomeObj> ns1 = [[SomeObj alloc] init];
263
+
// expected-warning@-1{{Incorrect use of RetainPtr constructor. The argument is +1 and results in a memory leak when ARC is disabled [alpha.webkit.RetainPtrCtorAdoptChecker]}}
264
+
auto ns2 = adoptNS([ns1.get() next]);
265
+
// expected-warning@-1{{Incorrect use of adoptNS. The argument is +0 and results in an use-after-free when ARC is disabled [alpha.webkit.RetainPtrCtorAdoptChecker]}}
// expected-warning@-1{{Incorrect use of RetainPtr constructor. The argument is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
// expected-warning@-1{{Incorrect use of adoptCF. The argument is +0 and results in an use-after-free when ARC is disabled [alpha.webkit.RetainPtrCtorAdoptChecker]}}
// expected-warning@-1{{Incorrect use of RetainPtr constructor. The argument is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
272
+
CFCopyArray(cf1);
273
+
// expected-warning@-1{{The return value is +1 and results in a memory leak [alpha.webkit.RetainPtrCtorAdoptChecker]}}
if ([[NSStringalloc] initWithUTF8String:"hello"]) {
286
+
}
287
+
}
288
+
289
+
-(void)make_some_obj {
290
+
auto some_obj = adoptNS([allocSomeObj() init]);
291
+
}
292
+
293
+
-(void)alloc_init_bad_order {
294
+
auto *obj = [NSObjectalloc];
295
+
auto ptr = adoptNS([obj init]);
296
+
// expected-warning@-1{{Incorrect use of adoptNS. The argument is +0 and results in an use-after-free when ARC is disabled [alpha.webkit.RetainPtrCtorAdoptChecker]}}
0 commit comments