From 6c1574bca5e3e2b99bb2f9a04face08ee36c7946 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 16 Sep 2016 11:50:57 +0000 Subject: [PATCH] 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 --- include/llvm/Target/TargetLoweringObjectFile.h | 2 +- lib/Target/TargetLoweringObjectFile.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h index b6cf0d88e63..b29d3a076a0 100644 --- a/include/llvm/Target/TargetLoweringObjectFile.h +++ b/include/llvm/Target/TargetLoweringObjectFile.h @@ -38,7 +38,7 @@ class TargetLoweringObjectFile : public MCObjectFileInfo { MCContext *Ctx; /// Name-mangler for global names. - Mangler *Mang; + Mangler *Mang = nullptr; TargetLoweringObjectFile( const TargetLoweringObjectFile&) = delete; diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index 1555c039c49..ae80075c7f8 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -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); -- 2.50.1