Skip to content

Commit

Permalink
[analyzer] StreamChecker: Remove now-unnecessary check::EndPath callb…
Browse files Browse the repository at this point in the history
…ack.

Also, don't bother to stop tracking symbols in the return value, either.
They are now properly considered live during checkDeadSymbols.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168069 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jrose-apple committed Nov 15, 2012
1 parent 7f82bc8 commit f34a579
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions lib/StaticAnalyzer/Checkers/StreamChecker.cpp
Expand Up @@ -57,9 +57,7 @@ struct StreamState {
};

class StreamChecker : public Checker<eval::Call,
check::DeadSymbols,
check::EndPath,
check::PreStmt<ReturnStmt> > {
check::DeadSymbols > {
mutable IdentifierInfo *II_fopen, *II_tmpfile, *II_fclose, *II_fread,
*II_fwrite,
*II_fseek, *II_ftell, *II_rewind, *II_fgetpos, *II_fsetpos,
Expand All @@ -75,8 +73,6 @@ class StreamChecker : public Checker<eval::Call,

bool evalCall(const CallExpr *CE, CheckerContext &C) const;
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
void checkEndPath(CheckerContext &Ctx) const;
void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;

private:
void Fopen(CheckerContext &C, const CallExpr *CE) const;
Expand Down Expand Up @@ -423,47 +419,6 @@ void StreamChecker::checkDeadSymbols(SymbolReaper &SymReaper,
}
}

void StreamChecker::checkEndPath(CheckerContext &Ctx) const {
ProgramStateRef state = Ctx.getState();
StreamMapTy M = state->get<StreamMap>();

for (StreamMapTy::iterator I = M.begin(), E = M.end(); I != E; ++I) {
StreamState SS = I->second;
if (SS.isOpened()) {
ExplodedNode *N = Ctx.addTransition(state);
if (N) {
if (!BT_ResourceLeak)
BT_ResourceLeak.reset(new BuiltinBug("Resource Leak",
"Opened File never closed. Potential Resource leak."));
BugReport *R = new BugReport(*BT_ResourceLeak,
BT_ResourceLeak->getDescription(), N);
Ctx.emitReport(R);
}
}
}
}

void StreamChecker::checkPreStmt(const ReturnStmt *S, CheckerContext &C) const {
const Expr *RetE = S->getRetValue();
if (!RetE)
return;

ProgramStateRef state = C.getState();
SymbolRef Sym = state->getSVal(RetE, C.getLocationContext()).getAsSymbol();

if (!Sym)
return;

const StreamState *SS = state->get<StreamMap>(Sym);
if(!SS)
return;

if (SS->isOpened())
state = state->set<StreamMap>(Sym, StreamState::getEscaped(S));

C.addTransition(state);
}

void ento::registerStreamChecker(CheckerManager &mgr) {
mgr.registerChecker<StreamChecker>();
}

0 comments on commit f34a579

Please sign in to comment.