]> granicus.if.org Git - clang/commitdiff
Add two new test cases for the Malloc/Free checker. Both have to do with
authorTed Kremenek <kremenek@apple.com>
Fri, 13 Nov 2009 20:00:28 +0000 (20:00 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 13 Nov 2009 20:00:28 +0000 (20:00 +0000)
storing malloc'ed memory to global storage.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88684 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/malloc.c

index acbfb4c38f36e0733d4a6521fcf86502b89d3137..45be977b93af029bffa856686dd5c2bca38d0119 100644 (file)
@@ -16,3 +16,21 @@ void f2() {
   free(p);
   free(p); // expected-warning{{Try to free a memory block that has been released}}
 }
+
+// This case tests that storing malloc'ed memory to a static variable which is then returned
+// is not leaked.  In the absence of known contracts for functions or inter-procedural analysis,
+// this is a conservative answer.
+int *f3() {
+  static int *p = 0;
+  p = malloc(10); // no-warning
+  return p;
+}
+
+// This case tests that storing malloc'ed memory to a static global variable which is then returned
+// is not leaked.  In the absence of known contracts for functions or inter-procedural analysis,
+// this is a conservative answer.
+static int *p_f4 = 0;
+int *f4() {
+  p_f4 = malloc(10); // no-warning
+  return p_f4;
+}