]> granicus.if.org Git - clang/commitdiff
[analyzer] Malloc Checker: Add another false positive as a todo test.
authorAnna Zaks <ganna@apple.com>
Wed, 15 Feb 2012 00:11:28 +0000 (00:11 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 15 Feb 2012 00:11:28 +0000 (00:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150534 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/malloc.c

index 2d62706ce4409263add2e20d5659c25596917e8b..ec9c19de880d00b351ff4c5e17073acef1e3d524 100644 (file)
@@ -11,6 +11,7 @@ void *calloc(size_t nmemb, size_t size);
 
 void myfoo(int *p);
 void myfooint(int p);
+char *fooRetPtr();
 
 void f1() {
   int *p = malloc(12);
@@ -441,6 +442,11 @@ void mallocFailedOrNotLeak() {
     return; // expected-warning {{Allocated memory never released. Potential memory leak.}}
 }
 
+void mallocAssignment() {
+  char *p = malloc(12);
+  p = fooRetPtr(); // expected-warning {{leak}}
+}
+
 int vallocTest() {
   char *mem = valloc(12);
   return 0; // expected-warning {{Allocated memory never released. Potential memory leak.}}
@@ -586,3 +592,11 @@ static void *specialMalloc(int n){
   }
   return p;// expected-warning {{Allocated memory never released. Potential memory leak.}}
 }
+
+// TODO: This is a false positve that should be fixed by making CString checker smarter.
+void symbolLostWithStrcpy(char *s) {
+  char *p = malloc(12);
+  p = strcpy(p, s);
+  free(p);// expected-warning {{leak}}
+}
+