diff options
author | Anna Zaks <ganna@apple.com> | 2012-06-22 22:42:30 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-06-22 22:42:30 +0000 |
commit | 26712c845e3967bc80d1ce6afb3e681f563b1a09 (patch) | |
tree | 8463474c8faa300f68ab754e475529e869be3821 /clang/test/Analysis/malloc.mm | |
parent | c98ebda325c996b3a12f4fded0368734dc0fe28a (diff) | |
download | bcm5719-llvm-26712c845e3967bc80d1ce6afb3e681f563b1a09.tar.gz bcm5719-llvm-26712c845e3967bc80d1ce6afb3e681f563b1a09.zip |
[analyzer] Teach malloc checker that initWith[Bytes|Characters}NoCopy
relinquish memory.
llvm-svn: 159043
Diffstat (limited to 'clang/test/Analysis/malloc.mm')
-rw-r--r-- | clang/test/Analysis/malloc.mm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.mm b/clang/test/Analysis/malloc.mm index 64135b2366a..7a9d881b151 100644 --- a/clang/test/Analysis/malloc.mm +++ b/clang/test/Analysis/malloc.mm @@ -21,6 +21,16 @@ void testNSDataFreeWhenDoneYES2(NSUInteger dataLength) { NSData *nsdata = [[NSData alloc] initWithBytesNoCopy:data length:dataLength freeWhenDone:1]; // no-warning } +void testNSStringFreeWhenDoneYES3(NSUInteger dataLength) { + unsigned char *data = (unsigned char *)malloc(42); + NSString *nsstr = [[NSString alloc] initWithBytesNoCopy:data length:dataLength encoding:NSUTF8StringEncoding freeWhenDone:1]; +} + +void testNSStringFreeWhenDoneYES4(NSUInteger dataLength) { + unichar *data = (unichar*)malloc(42); + NSString *nsstr = [[NSString alloc] initWithCharactersNoCopy:data length:dataLength freeWhenDone:1]; + free(data); //expected-warning {{Attempt to free non-owned memory}} +} void testNSStringFreeWhenDoneYES(NSUInteger dataLength) { unsigned char *data = (unsigned char *)malloc(42); |