Trying to fix Mangler memory leak in TargetLoweringObjectFile.

Summary:
`TargetLoweringObjectFile` can be re-used and thus `TargetLoweringObjectFile::Initialize()`
can be called multiple times causing `Mang` pointer memory leak.

Reviewers: echristo

Subscribers: llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D24659

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281718 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Liu 2016-09-16 11:50:57 +00:00
parent 793f0085f9
commit 6c1574bca5
2 changed files with 3 additions and 1 deletions

View File

@ -38,7 +38,7 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
MCContext *Ctx;
/// Name-mangler for global names.
Mangler *Mang;
Mangler *Mang = nullptr;
TargetLoweringObjectFile(
const TargetLoweringObjectFile&) = delete;

View File

@ -43,6 +43,8 @@ using namespace llvm;
void TargetLoweringObjectFile::Initialize(MCContext &ctx,
const TargetMachine &TM) {
Ctx = &ctx;
// `Initialize` can be called more than once.
if (Mang != nullptr) delete Mang;
Mang = new Mangler();
InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(),
TM.getCodeModel(), *Ctx);