summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-03-01 22:06:06 +0000
committerAnna Zaks <ganna@apple.com>2012-03-01 22:06:06 +0000
commit8dc53af5dcbbcbb00faf3ed3cc3e62c982007144 (patch)
treef2160b07547dd047fcae5ddf710f974457a3242c /clang
parentb4f6a5118459e11e6c21d66899d4791714729e33 (diff)
downloadbcm5719-llvm-8dc53af5dcbbcbb00faf3ed3cc3e62c982007144.tar.gz
bcm5719-llvm-8dc53af5dcbbcbb00faf3ed3cc3e62c982007144.zip
[analyzer] Fix a regression introduced in malloc with
attributes, introduced in r151188. + the test to catch it. Thanks to Ahmed Charles for pointing this out. llvm-svn: 151840
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp10
-rw-r--r--clang/test/Analysis/malloc-annotations.c9
2 files changed, 16 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index ae81ad6eda0..b74317cc98b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -442,12 +442,16 @@ ProgramStateRef MallocChecker::FreeMemAttr(CheckerContext &C,
if (Att->getModule() != "malloc")
return 0;
+ ProgramStateRef State = C.getState();
+
for (OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end();
I != E; ++I) {
- return FreeMemAux(C, CE, C.getState(), *I,
- Att->getOwnKind() == OwnershipAttr::Holds);
+ ProgramStateRef StateI = FreeMemAux(C, CE, State, *I,
+ Att->getOwnKind() == OwnershipAttr::Holds);
+ if (StateI)
+ State = StateI;
}
- return 0;
+ return State;
}
ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C,
diff --git a/clang/test/Analysis/malloc-annotations.c b/clang/test/Analysis/malloc-annotations.c
index 70b55ebda2b..fbc6391ea50 100644
--- a/clang/test/Analysis/malloc-annotations.c
+++ b/clang/test/Analysis/malloc-annotations.c
@@ -6,6 +6,8 @@ void *realloc(void *ptr, size_t size);
void *calloc(size_t nmemb, size_t size);
void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
void __attribute((ownership_takes(malloc, 1))) my_free(void *);
+void my_freeBoth(void *, void *)
+ __attribute((ownership_holds(malloc, 1, 2)));
void __attribute((ownership_returns(malloc, 1))) *my_malloc2(size_t);
void __attribute((ownership_holds(malloc, 1))) my_hold(void *);
@@ -260,3 +262,10 @@ char callocZeroesBad () {
}
return result; // expected-warning{{never released}}
}
+
+void testMultipleFreeAnnotations() {
+ int *p = malloc(12);
+ int *q = malloc(12);
+ my_freeBoth(p, q);
+}
+
OpenPOWER on IntegriCloud