[cfe-commits] r150158 - /cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Anna Zaks ganna at apple.com
Wed Feb 8 22:48:19 PST 2012


Author: zaks
Date: Thu Feb  9 00:48:19 2012
New Revision: 150158

URL: http://llvm.org/viewvc/llvm-project?rev=150158&view=rev
Log:
[analyzer] MallocChecker: address a diagnostic "fixme".

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=150158&r1=150157&r2=150158&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Thu Feb  9 00:48:19 2012
@@ -651,12 +651,13 @@
   RegionStateTy::Factory &F = state->get_context<RegionState>();
 
   bool generateReport = false;
-  
+  llvm::SmallVector<SymbolRef, 2> Errors;
   for (RegionStateTy::iterator I = RS.begin(), E = RS.end(); I != E; ++I) {
     if (SymReaper.isDead(I->first)) {
-      if (I->second.isAllocated())
+      if (I->second.isAllocated()) {
         generateReport = true;
-
+        Errors.push_back(I->first);
+      }
       // Remove the dead symbol from the map.
       RS = F.remove(RS, I->first);
 
@@ -665,17 +666,16 @@
   
   ExplodedNode *N = C.addTransition(state->set<RegionState>(RS));
 
-  // FIXME: This does not handle when we have multiple leaks at a single
-  // place.
-  // TODO: We don't have symbol info in the diagnostics here!
   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);
-    //Report->addVisitor(new MallocBugVisitor(Sym));
-    C.EmitReport(R);
+          "Allocated memory never released. Potential memory leak."));
+    for (llvm::SmallVector<SymbolRef, 2>::iterator
+          I = Errors.begin(), E = Errors.end(); I != E; ++I) {
+      BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
+      R->addVisitor(new MallocBugVisitor(*I));
+      C.EmitReport(R);
+    }
   }
 }
 





More information about the cfe-commits mailing list