Skip to content

Commit d07ad51

Browse files
author
Eric Liu
committed
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 llvm-svn: 281718
1 parent 7f193d6 commit d07ad51

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

llvm/include/llvm/Target/TargetLoweringObjectFile.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
3838
MCContext *Ctx;
3939

4040
/// Name-mangler for global names.
41-
Mangler *Mang;
41+
Mangler *Mang = nullptr;
4242

4343
TargetLoweringObjectFile(
4444
const TargetLoweringObjectFile&) = delete;

llvm/lib/Target/TargetLoweringObjectFile.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ using namespace llvm;
4343
void TargetLoweringObjectFile::Initialize(MCContext &ctx,
4444
const TargetMachine &TM) {
4545
Ctx = &ctx;
46+
// `Initialize` can be called more than once.
47+
if (Mang != nullptr) delete Mang;
4648
Mang = new Mangler();
4749
InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(),
4850
TM.getCodeModel(), *Ctx);

0 commit comments

Comments
 (0)