]> granicus.if.org Git - llvm/commitdiff
Trying to fix Mangler memory leak in TargetLoweringObjectFile.
authorEric Liu <ioeric@google.com>
Fri, 16 Sep 2016 11:50:57 +0000 (11:50 +0000)
committerEric Liu <ioeric@google.com>
Fri, 16 Sep 2016 11:50:57 +0000 (11:50 +0000)
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
lib/Target/TargetLoweringObjectFile.cpp

index b6cf0d88e63c03113eb638745980f12ae089d2a9..b29d3a076a005f336addc6371d8ecf822579fbeb 100644 (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;
index 1555c039c495a74de23ce52e87735e9af79359db..ae80075c7f83428d580227bc8108547fd62986c9 100644 (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);