summaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-02-22 02:36:01 +0000
committerAnna Zaks <ganna@apple.com>2012-02-22 02:36:01 +0000
commitd9ab7bbbd43639247c9a82c8e8dbfaa617f4e266 (patch)
tree525bcd52b30dbc978419af69f3ac289d472e1d96 /lib/StaticAnalyzer/Checkers/MallocChecker.cpp
parent5fdadf4b643dd2f7a467244946dc1587b2f9ed1f (diff)
downloadclang-d9ab7bbbd43639247c9a82c8e8dbfaa617f4e266.tar.gz
clang-d9ab7bbbd43639247c9a82c8e8dbfaa617f4e266.tar.bz2
clang-d9ab7bbbd43639247c9a82c8e8dbfaa617f4e266.tar.xz
[analyzer] Malloc: fix another false positive.
, when we return a symbol reachable to the malloced one via pointer arithmetic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151121 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r--lib/StaticAnalyzer/Checkers/MallocChecker.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fed64f1b04..e21dde1f82 100644
--- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -881,7 +881,17 @@ void MallocChecker::checkPreStmt(const ReturnStmt *S, CheckerContext &C) const {
return;
// Check if we are returning a symbol.
- SymbolRef Sym = C.getState()->getSVal(E, C.getLocationContext()).getAsSymbol();
+ SVal RetVal = C.getState()->getSVal(E, C.getLocationContext());
+ SymbolRef Sym = RetVal.getAsSymbol();
+ if (!Sym)
+ // If we are returning a field of the allocated struct or an array element,
+ // the callee could still free the memory.
+ // TODO: This logic should be a part of generic symbol escape callback.
+ if (const MemRegion *MR = RetVal.getAsRegion())
+ if (isa<FieldRegion>(MR) || isa<ElementRegion>(MR))
+ if (const SymbolicRegion *BMR =
+ dyn_cast<SymbolicRegion>(MR->getBaseRegion()))
+ Sym = BMR->getSymbol();
if (!Sym)
return;