diff options
author | Anna Zaks <ganna@apple.com> | 2012-11-02 21:30:04 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-11-02 21:30:04 +0000 |
commit | edd07f40ce13eb64537e9bd3af2bec4847a90fb2 (patch) | |
tree | 5a26da5e05136cc61225f7117870e1efc752a197 /lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp | |
parent | 9417b05ef982bd3dbcae2fa24083b5be00d6c4f1 (diff) |
[analyzer] Factor SimpleStreamChecker pulling out isLeaked().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp index 203271afcb..fd548bc1b0 100644 --- a/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp @@ -136,29 +136,35 @@ void SimpleStreamChecker::checkPreStmt(const CallExpr *Call, C.addTransition(State); } +static bool isLeaked(SymbolRef Sym, const StreamState &SS, + bool IsSymDead, ProgramStateRef State) { + if (IsSymDead && SS.isOpened()) { + // If a symbol is NULL, assume that fopen failed on this path. + // A symbol should only be considered leaked if it is non-null. + ConstraintManager &CMgr = State->getConstraintManager(); + ConditionTruthVal OpenFailed = CMgr.isNull(State, Sym); + return !OpenFailed.isConstrainedTrue(); + } + return false; +} + void SimpleStreamChecker::checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const { ProgramStateRef State = C.getState(); - StreamMapTy TrackedStreams = State->get<StreamMap>(); - SymbolVector LeakedStreams; + StreamMapTy TrackedStreams = State->get<StreamMap>(); for (StreamMapTy::iterator I = TrackedStreams.begin(), E = TrackedStreams.end(); I != E; ++I) { SymbolRef Sym = I->first; - if (SymReaper.isDead(Sym)) { - const StreamState &SS = I->second; - if (SS.isOpened()) { - // If a symbol is NULL, assume that fopen failed on this path - // and do not report a leak. - ConstraintManager &CMgr = State->getConstraintManager(); - ConditionTruthVal OpenFailed = CMgr.isNull(State, Sym); - if (!OpenFailed.isConstrainedTrue()) - LeakedStreams.push_back(Sym); - } - - // Remove the dead symbol from the streams map. + bool IsSymDead = SymReaper.isDead(Sym); + + // Collect leaked symbols. + if (isLeaked(Sym, I->second, IsSymDead, State)) + LeakedStreams.push_back(Sym); + + // Remove the dead symbol from the streams map. + if (IsSymDead) State = State->remove<StreamMap>(Sym); - } } ExplodedNode *N = C.addTransition(State); |