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 StreamChecker::checkEndPath(CheckerContext &Ctx) const {
  const ProgramState *state = Ctx.getState();
  typedef llvm::ImmutableMap<SymbolRef, StreamState> SymMap;
  SymMap M = state->get<StreamState>();
  
  for (SymMap::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);
      }
    }
  }
}
Esempio n. 3
0
void StreamChecker::checkEndPath(EndOfFunctionNodeBuilder &B,
                                 ExprEngine &Eng) const {
    const GRState *state = B.getState();
    typedef llvm::ImmutableMap<SymbolRef, StreamState> SymMap;
    SymMap M = state->get<StreamState>();

    for (SymMap::iterator I = M.begin(), E = M.end(); I != E; ++I) {
        StreamState SS = I->second;
        if (SS.isOpened()) {
            ExplodedNode *N = B.generateNode(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);
                Eng.getBugReporter().EmitReport(R);
            }
        }
    }
}