Skip to content

Commit

Permalink
Fix memory leak in LLVMTargetMachine.cpp (llvm#109610)
Browse files Browse the repository at this point in the history
Because `MAB` is a raw pointer, it could potentially leak memory because
of the `||` in the null check.
  • Loading branch information
abhishek-kaushik22 authored Sep 23, 2024
1 parent 0b0a37e commit f28a035
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/LLVMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
const MCRegisterInfo &MRI = *getMCRegisterInfo();
std::unique_ptr<MCCodeEmitter> MCE(
getTarget().createMCCodeEmitter(*getMCInstrInfo(), *Ctx));
if (!MCE)
return true;
MCAsmBackend *MAB =
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions);
if (!MCE || !MAB)
if (!MAB)
return true;

const Triple &T = getTargetTriple();
Expand Down

0 comments on commit f28a035

Please sign in to comment.