Fix leaks in LLVMCreateDisasmCPUFeatures

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

llvm-svn: 364444
This commit is contained in:
Scott Linder 2019-06-26 16:13:17 +00:00
parent c8232e4310
commit c95046501d
2 changed files with 31 additions and 31 deletions

View File

@ -52,31 +52,32 @@ LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU,
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 *TT, const char *CPU,
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;

View File

@ -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; }