]> granicus.if.org Git - clang/commitdiff
[analyzer] fix bug in malloc checker where the tracked symbol would not properly...
authorTed Kremenek <kremenek@apple.com>
Thu, 28 Jul 2011 23:07:51 +0000 (23:07 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 28 Jul 2011 23:07:51 +0000 (23:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136418 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp

index e49ff9f581416d4f8956664e1e8cdebb67397e46..9ba6eb2fed46451c96a57857e9713369e28fd7ae 100644 (file)
@@ -578,24 +578,31 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
   RegionStateTy RS = state->get<RegionState>();
   RegionStateTy::Factory &F = state->get_context<RegionState>();
 
+  bool generateReport = false;
+  
   for (RegionStateTy::iterator I = RS.begin(), E = RS.end(); I != E; ++I) {
     if (SymReaper.isDead(I->first)) {
-      if (I->second.isAllocated()) {
-        if (ExplodedNode *N = C.generateNode()) {
-          if (!BT_Leak)
-            BT_Leak.reset(new BuiltinBug("Memory leak",
-                    "Allocated memory never released. Potential memory leak."));
-          // FIXME: where it is allocated.
-          BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
-          C.EmitReport(R);
-        }
-      }
+      if (I->second.isAllocated())
+        generateReport = true;
 
       // Remove the dead symbol from the map.
       RS = F.remove(RS, I->first);
+
     }
   }
-  C.generateNode(state->set<RegionState>(RS));
+  
+  ExplodedNode *N = C.generateNode(state->set<RegionState>(RS));
+
+  // FIXME: This does not handle when we have multiple leaks at a single
+  // place.
+  if (N && generateReport) {
+    if (!BT_Leak)
+      BT_Leak.reset(new BuiltinBug("Memory leak",
+              "Allocated memory never released. Potential memory leak."));
+    // FIXME: where it is allocated.
+    BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
+    C.EmitReport(R);
+  }
 }
 
 void MallocChecker::checkEndPath(EndOfFunctionNodeBuilder &B,