aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/Analysis/malloc.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c
index acbfb4c38f..45be977b93 100644
--- a/test/Analysis/malloc.c
+++ b/test/Analysis/malloc.c
@@ -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;
+}