]> granicus.if.org Git - clang/commitdiff
[analyzer] Eliminate memory leak in BugReporter::emitReport()
authorAnton Yartsev <anton.yartsev@gmail.com>
Mon, 10 Mar 2014 22:35:02 +0000 (22:35 +0000)
committerAnton Yartsev <anton.yartsev@gmail.com>
Mon, 10 Mar 2014 22:35:02 +0000 (22:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203507 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/BugReporter.cpp

index 1b55cdec589c4fe409cbfd8b06059805c1b0e58d..387a0eb396e8217927fa0b0a52b7ecfabc372d48 100644 (file)
@@ -3243,6 +3243,9 @@ void BugReporter::Register(BugType *BT) {
 }
 
 void BugReporter::emitReport(BugReport* R) {
+  // To guarantee memory release.
+  std::unique_ptr<BugReport> UniqueR(R);
+
   // Defensive checking: throw the bug away if it comes from a BodyFarm-
   // generated body. We do this very early because report processing relies
   // on the report's location being valid.
@@ -3273,12 +3276,12 @@ void BugReporter::emitReport(BugReport* R) {
   BugReportEquivClass* EQ = EQClasses.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!EQ) {
-    EQ = new BugReportEquivClass(R);
+    EQ = new BugReportEquivClass(UniqueR.release());
     EQClasses.InsertNode(EQ, InsertPos);
     EQClassesVector.push_back(EQ);
   }
   else
-    EQ->AddReport(R);
+    EQ->AddReport(UniqueR.release());
 }