aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/malloc.c
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-16 00:09:20 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-16 00:09:20 +0000
commit1bf908df57cc43f3bc7296f4e51f5708bd323c6b (patch)
tree6168abf1a59d940bcbbc9c711f288e7b889afab7 /test/Analysis/malloc.c
parent32f498a675df990901e6659d610dc740f9423228 (diff)
[analyzer] Buffers passed to CGBitmapContextCreate can escape.
Specifically, although the bitmap context does not take ownership of the buffer (unlike CGBitmapContextCreateWithData), the data buffer can be extracted out of the created CGContextRef. Thus the buffer is not leaked even if its original pointer goes out of scope, as long as - the context escapes, or - it is retrieved via CGBitmapContextGetData and freed. Actually implementing that logic is beyond the current scope of MallocChecker, so for now CGBitmapContextCreate goes on our system function exception list. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158579 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r--test/Analysis/malloc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c
index 7c2196ac9e..c532d6813f 100644
--- a/test/Analysis/malloc.c
+++ b/test/Analysis/malloc.c
@@ -955,3 +955,22 @@ void test_double_assign_ints_positive()
(void*)(long)(unsigned long)ptr; // expected-warning {{unused}} expected-warning {{leak}}
}
+
+void testCGContextNoLeak()
+{
+ void *ptr = malloc(16);
+ CGContextRef context = CGBitmapContextCreate(ptr);
+
+ // Because you can get the data back out like this, even much later,
+ // CGBitmapContextCreate is one of our "stop-tracking" exceptions.
+ free(CGBitmapContextGetData(context));
+}
+
+void testCGContextLeak()
+{
+ void *ptr = malloc(16);
+ CGContextRef context = CGBitmapContextCreate(ptr);
+ // However, this time we're just leaking the data, because the context
+ // object doesn't escape and it hasn't been freed in this function.
+}
+