summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/malloc.c
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-02-29 18:42:47 +0000
committerAnna Zaks <ganna@apple.com>2012-02-29 18:42:47 +0000
commite0c03cab58c92716882c09b279cd07417ba3ffca (patch)
tree05a674b3103521a7eb3ffb292a8e9a943172607d /clang/test/Analysis/malloc.c
parent64d6eb1195796726f5096f84c281ca22b68aa295 (diff)
downloadbcm5719-llvm-e0c03cab58c92716882c09b279cd07417ba3ffca.tar.gz
bcm5719-llvm-e0c03cab58c92716882c09b279cd07417ba3ffca.zip
[analyzer] Malloc: A pointer might escape through CFContainers APIs,
funopen, setvbuf. Teach the checker and the engine about these APIs to resolve malloc false positives. As I am adding more of these APIs, it is clear that all this should be factored out into a separate callback (for example, region escapes). Malloc, KeyChainAPI and RetainRelease checkers could all use it. llvm-svn: 151737
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r--clang/test/Analysis/malloc.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index f9e3663494b..bfe1befb530 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -677,7 +677,9 @@ void testStrdupContentIsDefined(const char *s, unsigned validIndex) {
free(s2);
}
+// ----------------------------------------------------------------------------
// Test the system library functions to which the pointer can escape.
+// This tests false positive suppression.
// For now, we assume memory passed to pthread_specific escapes.
// TODO: We could check that if a new pthread binding is set, the existing
@@ -687,6 +689,46 @@ void testPthereadSpecificEscape(pthread_key_t key) {
pthread_setspecific(key, buf); // no warning
}
+// PR12101: Test funopen().
+static int releasePtr(void *_ctx) {
+ free(_ctx);
+ return 0;
+}
+FILE *useFunOpen() {
+ void *ctx = malloc(sizeof(int));
+ FILE *f = funopen(ctx, 0, 0, 0, releasePtr); // no warning
+ if (f == 0) {
+ free(ctx);
+ }
+ return f;
+}
+FILE *useFunOpenNoReleaseFunction() {
+ void *ctx = malloc(sizeof(int));
+ FILE *f = funopen(ctx, 0, 0, 0, 0);
+ if (f == 0) {
+ free(ctx);
+ }
+ return f; // expected-warning{{leak}}
+}
+
+// Test setbuf, setvbuf.
+int my_main_no_warning() {
+ char *p = malloc(100);
+ setvbuf(stdout, p, 0, 100);
+ return 0;
+}
+int my_main_no_warning2() {
+ char *p = malloc(100);
+ setbuf(__stdoutp, p);
+ return 0;
+}
+int my_main_warn(FILE *f) {
+ char *p = malloc(100);
+ setvbuf(f, p, 0, 100);
+ return 0;// expected-warning {{leak}}
+}
+
+// ----------------------------------------------------------------------------
// Below are the known false positives.
// TODO: There should be no warning here. This one might be difficult to get rid of.
@@ -706,6 +748,7 @@ void dependsOnValueOfPtr(int *g, unsigned f) {
return;
}
+// ----------------------------------------------------------------------------
// False negatives.
// TODO: This requires tracking symbols stored inside the structs/arrays.
OpenPOWER on IntegriCloud