[cfe-commits] r88684 - /cfe/trunk/test/Analysis/malloc.c

Ted Kremenek kremenek at apple.com
Fri Nov 13 12:00:28 PST 2009


Author: kremenek
Date: Fri Nov 13 14:00:28 2009
New Revision: 88684

URL: http://llvm.org/viewvc/llvm-project?rev=88684&view=rev
Log:
Add two new test cases for the Malloc/Free checker.  Both have to do with
storing malloc'ed memory to global storage.

Modified:
    cfe/trunk/test/Analysis/malloc.c

Modified: cfe/trunk/test/Analysis/malloc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=88684&r1=88683&r2=88684&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Fri Nov 13 14:00:28 2009
@@ -16,3 +16,21 @@
   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;
+}





More information about the cfe-commits mailing list