From e018c7b00c8d3b4c506efe266bf30f77f7d9b589 Mon Sep 17 00:00:00 2001 From: Anton Yartsev Date: Mon, 10 Mar 2014 22:35:02 +0000 Subject: [PATCH] [analyzer] Eliminate memory leak in BugReporter::emitReport() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203507 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/BugReporter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index 1b55cdec58..387a0eb396 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -3243,6 +3243,9 @@ void BugReporter::Register(BugType *BT) { } void BugReporter::emitReport(BugReport* R) { + // To guarantee memory release. + std::unique_ptr 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()); } -- 2.40.0