aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-06-22 02:04:31 +0000
committerAnna Zaks <ganna@apple.com>2012-06-22 02:04:31 +0000
commit5b7aa34167f23e6137bd257addac4dd67f612ec4 (patch)
tree25ef919b70a0ef850dbeb287f563178d5acf32bb /test/Analysis
parent0764573a17b0796427f505c1cc7b53c33aeba25e (diff)
[analyzer] Malloc: Warn about use-after-free when memory ownership was
transfered with dataWithBytesNoCopy. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158958 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/malloc-annotations.c3
-rw-r--r--test/Analysis/malloc.mm17
2 files changed, 12 insertions, 8 deletions
diff --git a/test/Analysis/malloc-annotations.c b/test/Analysis/malloc-annotations.c
index 15ce62d9a5..089e53132d 100644
--- a/test/Analysis/malloc-annotations.c
+++ b/test/Analysis/malloc-annotations.c
@@ -124,11 +124,10 @@ void af2e() {
}
// This case inflicts a possible double-free.
-// TODO: Better error message.
void af3() {
int *p = my_malloc(12);
my_hold(p);
- free(p); // expected-warning{{Attempt to free released memory}}
+ free(p); // expected-warning{{Attempt to free non-owned memory}}
}
int * af4() {
diff --git a/test/Analysis/malloc.mm b/test/Analysis/malloc.mm
index 855892da2b..23297ec97c 100644
--- a/test/Analysis/malloc.mm
+++ b/test/Analysis/malloc.mm
@@ -9,7 +9,6 @@ void free(void *);
void testNSDatafFreeWhenDoneNoError(NSUInteger dataLength) {
unsigned char *data = (unsigned char *)malloc(42);
NSData *nsdata = [NSData dataWithBytesNoCopy:data length:dataLength];
- free(data); // no warning
}
void testNSDataFreeWhenDoneYES(NSUInteger dataLength) {
@@ -55,11 +54,17 @@ void testNSStringFreeWhenDoneNO2(NSUInteger dataLength) {
NSString *nsstr = [[NSString alloc] initWithCharactersNoCopy:data length:dataLength freeWhenDone:0]; // expected-warning{{leak}}
}
-// TODO: False Negative.
-void testNSDatafFreeWhenDoneFN(NSUInteger dataLength) {
- unsigned char *data = (unsigned char *)malloc(42);
- NSData *nsdata = [NSData dataWithBytesNoCopy:data length:dataLength freeWhenDone:1];
- free(data); // false negative
+void testRelinquished1() {
+ void *data = malloc(42);
+ NSData *nsdata = [NSData dataWithBytesNoCopy:data length:42 freeWhenDone:1];
+ free(data); // expected-warning {{Attempt to free non-owned memory}}
+}
+
+void testRelinquished2() {
+ void *data = malloc(42);
+ NSData *nsdata;
+ free(data);
+ [NSData dataWithBytesNoCopy:data length:42]; // expected-warning {{Attempt to free released memory}}
}
// Test CF/NS...NoCopy. PR12100: Pointers can escape when custom deallocators are provided.