summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2013-05-31 23:47:32 +0000
committerAnna Zaks <ganna@apple.com>2013-05-31 23:47:32 +0000
commita4bc5e120173fc6059cc119971f290067b8ba1e9 (patch)
treed5ecc8cac60f5eb6679d8489f52688cacbd4541f /clang/test
parentb1a4d9da3b7d48c40e6abee2acc9f6324dad7f84 (diff)
downloadbcm5719-llvm-a4bc5e120173fc6059cc119971f290067b8ba1e9.tar.gz
bcm5719-llvm-a4bc5e120173fc6059cc119971f290067b8ba1e9.zip
[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
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/Inputs/system-header-simulator-objc.h1
-rw-r--r--clang/test/Analysis/malloc.m11
2 files changed, 9 insertions, 3 deletions
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-objc.h b/clang/test/Analysis/Inputs/system-header-simulator-objc.h
index ecc99e17c49..3e1d9555bbd 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-objc.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-objc.h
@@ -102,6 +102,7 @@ typedef double NSTimeInterval;
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;
- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;
- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;
+- (id)initWithBytes:(void *)bytes length:(NSUInteger) length;
@end
typedef struct {
diff --git a/clang/test/Analysis/malloc.m b/clang/test/Analysis/malloc.m
index 4c1e161db2d..ad16db52dff 100644
--- a/clang/test/Analysis/malloc.m
+++ b/clang/test/Analysis/malloc.m
@@ -35,13 +35,18 @@ void rdar10579586(char x);
}
@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
OpenPOWER on IntegriCloud