[llvm] r364444 - Fix leaks in LLVMCreateDisasmCPUFeatures
Scott Linder via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 09:13:18 PDT 2019
Author: scott.linder
Date: Wed Jun 26 09:13:17 2019
New Revision: 364444
URL: http://llvm.org/viewvc/llvm-project?rev=364444&view=rev
Log:
Fix leaks in LLVMCreateDisasmCPUFeatures
Differential Revision: https://reviews.llvm.org/D63795
Modified:
llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
llvm/trunk/lib/MC/MCDisassembler/Disassembler.h
Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=364444&r1=364443&r2=364444&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)
+++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Wed Jun 26 09:13:17 2019
@@ -52,31 +52,32 @@ LLVMCreateDisasmCPUFeatures(const char *
if (!TheTarget)
return nullptr;
- const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(TT);
+ std::unique_ptr<const MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
if (!MRI)
return nullptr;
// Get the assembler info needed to setup the MCContext.
- const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(*MRI, TT);
+ std::unique_ptr<const MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TT));
if (!MAI)
return nullptr;
- const MCInstrInfo *MII = TheTarget->createMCInstrInfo();
+ std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
if (!MII)
return nullptr;
- const MCSubtargetInfo *STI =
- TheTarget->createMCSubtargetInfo(TT, CPU, Features);
+ std::unique_ptr<const MCSubtargetInfo> STI(
+ TheTarget->createMCSubtargetInfo(TT, CPU, Features));
if (!STI)
return nullptr;
// Set up the MCContext for creating symbols and MCExpr's.
- MCContext *Ctx = new MCContext(MAI, MRI, nullptr);
+ std::unique_ptr<MCContext> Ctx(new MCContext(MAI.get(), MRI.get(), nullptr));
if (!Ctx)
return nullptr;
// Set up disassembler.
- MCDisassembler *DisAsm = TheTarget->createMCDisassembler(*STI, *Ctx);
+ std::unique_ptr<MCDisassembler> DisAsm(
+ TheTarget->createMCDisassembler(*STI, *Ctx));
if (!DisAsm)
return nullptr;
@@ -86,19 +87,20 @@ LLVMCreateDisasmCPUFeatures(const char *
return nullptr;
std::unique_ptr<MCSymbolizer> Symbolizer(TheTarget->createMCSymbolizer(
- TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo)));
+ TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx.get(), std::move(RelInfo)));
DisAsm->setSymbolizer(std::move(Symbolizer));
// Set up the instruction printer.
int AsmPrinterVariant = MAI->getAssemblerDialect();
- MCInstPrinter *IP = TheTarget->createMCInstPrinter(
- Triple(TT), AsmPrinterVariant, *MAI, *MII, *MRI);
+ std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
+ Triple(TT), AsmPrinterVariant, *MAI, *MII, *MRI));
if (!IP)
return nullptr;
- LLVMDisasmContext *DC =
- new LLVMDisasmContext(TT, DisInfo, TagType, GetOpInfo, SymbolLookUp,
- TheTarget, MAI, MRI, STI, MII, Ctx, DisAsm, IP);
+ LLVMDisasmContext *DC = new LLVMDisasmContext(
+ TT, DisInfo, TagType, GetOpInfo, SymbolLookUp, TheTarget, std::move(MAI),
+ std::move(MRI), std::move(STI), std::move(MII), std::move(Ctx),
+ std::move(DisAsm), std::move(IP));
if (!DC)
return nullptr;
Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.h?rev=364444&r1=364443&r2=364444&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDisassembler/Disassembler.h (original)
+++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.h Wed Jun 26 09:13:17 2019
@@ -82,24 +82,22 @@ public:
SmallString<128> CommentsToEmit;
raw_svector_ostream CommentStream;
- LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
- LLVMOpInfoCallback getOpInfo,
- LLVMSymbolLookupCallback symbolLookUp,
- const Target *theTarget, const MCAsmInfo *mAI,
- const MCRegisterInfo *mRI, const MCSubtargetInfo *mSI,
- const MCInstrInfo *mII, llvm::MCContext *ctx,
- const MCDisassembler *disAsm, MCInstPrinter *iP)
- : TripleName(std::move(tripleName)), DisInfo(disInfo), TagType(tagType),
- GetOpInfo(getOpInfo), SymbolLookUp(symbolLookUp), TheTarget(theTarget),
- Options(0), CommentStream(CommentsToEmit) {
- MAI.reset(mAI);
- MRI.reset(mRI);
- MSI.reset(mSI);
- MII.reset(mII);
- Ctx.reset(ctx);
- DisAsm.reset(disAsm);
- IP.reset(iP);
- }
+ LLVMDisasmContext(std::string TripleName, void *DisInfo, int TagType,
+ LLVMOpInfoCallback GetOpInfo,
+ LLVMSymbolLookupCallback SymbolLookUp,
+ const Target *TheTarget,
+ std::unique_ptr<const MCAsmInfo> &&MAI,
+ std::unique_ptr<const MCRegisterInfo> &&MRI,
+ std::unique_ptr<const MCSubtargetInfo> &&MSI,
+ std::unique_ptr<const MCInstrInfo> &&MII,
+ std::unique_ptr<const llvm::MCContext> &&Ctx,
+ std::unique_ptr<const MCDisassembler> &&DisAsm,
+ std::unique_ptr<MCInstPrinter> &&IP)
+ : TripleName(std::move(TripleName)), DisInfo(DisInfo), TagType(TagType),
+ GetOpInfo(GetOpInfo), SymbolLookUp(SymbolLookUp), TheTarget(TheTarget),
+ MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)),
+ MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)),
+ IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {}
const std::string &getTripleName() const { return TripleName; }
void *getDisInfo() const { return DisInfo; }
int getTagType() const { return TagType; }
More information about the llvm-commits
mailing list