r203507 - [analyzer] Eliminate memory leak in BugReporter::emitReport()
Anton Yartsev
anton.yartsev at gmail.com
Mon Mar 10 15:35:02 PDT 2014
Author: ayartsev
Date: Mon Mar 10 17:35:02 2014
New Revision: 203507
URL: http://llvm.org/viewvc/llvm-project?rev=203507&view=rev
Log:
[analyzer] Eliminate memory leak in BugReporter::emitReport()
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=203507&r1=203506&r2=203507&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Mon Mar 10 17:35:02 2014
@@ -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*
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());
}
More information about the cfe-commits
mailing list