[llvm] f28a035 - Fix memory leak in LLVMTargetMachine.cpp (#109610)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 02:12:00 PDT 2024


Author: abhishek-kaushik22
Date: 2024-09-23T17:11:56+08:00
New Revision: f28a0355364b9f09fa3d47720af4cf7431721de6

URL: https://github.com/llvm/llvm-project/commit/f28a0355364b9f09fa3d47720af4cf7431721de6
DIFF: https://github.com/llvm/llvm-project/commit/f28a0355364b9f09fa3d47720af4cf7431721de6.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/LLVMTargetMachine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index d0dfafeaef561f..4ff22057b290f5 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -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();


        


More information about the llvm-commits mailing list