[analyzer] Malloc checker should only escape the receiver when “[O init..]” is called.
Jordan has pointed out that it is valuable to warn in cases when the arguments to init escape.
For example, NSData initWithBytes id not going to free the memory.
llvm-svn: 183062
diff --git a/clang/test/Analysis/malloc.m b/clang/test/Analysis/malloc.m
index 4c1e161..ad16db5 100644
--- a/clang/test/Analysis/malloc.m
+++ b/clang/test/Analysis/malloc.m
@@ -35,13 +35,18 @@
}
@end
-@interface JKArray : NSObject {
+@interface MyArray : NSObject {
id * objects;
}
@end
-void _JKArrayCreate() {
- JKArray *array = (JKArray *)malloc(12);
+void _ArrayCreate() {
+ MyArray *array = (MyArray *)malloc(12);
array = [array init];
free(array); // no-warning
+}
+
+void testNSDataTruePositiveLeak() {
+ char *b = (char *)malloc(12);
+ NSData *d = [[NSData alloc] initWithBytes: b length: 12]; // expected-warning {{Potential leak of memory pointed to by 'b'}}
}
\ No newline at end of file