Skip to content

Commit f28a035

Browse files
Fix memory leak in LLVMTargetMachine.cpp (#109610)
Because `MAB` is a raw pointer, it could potentially leak memory because of the `||` in the null check.
1 parent 0b0a37e commit f28a035

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
259259
const MCRegisterInfo &MRI = *getMCRegisterInfo();
260260
std::unique_ptr<MCCodeEmitter> MCE(
261261
getTarget().createMCCodeEmitter(*getMCInstrInfo(), *Ctx));
262+
if (!MCE)
263+
return true;
262264
MCAsmBackend *MAB =
263265
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions);
264-
if (!MCE || !MAB)
266+
if (!MAB)
265267
return true;
266268

267269
const Triple &T = getTargetTriple();

0 commit comments

Comments
 (0)