[llvm] 3657e77 - Add delete to fix resource leak in llc.cpp

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 23:50:53 PDT 2023


Author: Wang, Xin10
Date: 2023-04-12T02:50:39-04:00
New Revision: 3657e7777f208a35981108592330d4ad7486cb14

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

LOG: Add delete to fix resource leak in llc.cpp

>From line 693 in file llc.cpp, it uses new operator to creates a ModulePass
and assigned to MMIWP. If the condition after take the true branch, it has
chance to go in to line 702 or line 709, the function will return without
cleaning the memory.
The second issue existed for the same reason, the ref TPC get the pointer
created from LLVMTM.createPassConfig, and will leak memory if goes into
line 709.
This patch uses delete in the issued branch.

Reviewed By: craig.topper

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

Added: 
    

Modified: 
    llvm/tools/llc/llc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 0764968b4c22c..50a2257d02f29 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -699,13 +699,17 @@ static int compileModule(char **argv, LLVMContext &Context) {
       if (!MIR) {
         WithColor::warning(errs(), argv[0])
             << "run-pass is for .mir file only.\n";
+        delete MMIWP;
         return 1;
       }
-      TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM);
+      TargetPassConfig *PTPC = LLVMTM.createPassConfig(PM);
+      TargetPassConfig &TPC = *PTPC;
       if (TPC.hasLimitedCodeGenPipeline()) {
         WithColor::warning(errs(), argv[0])
             << "run-pass cannot be used with "
             << TPC.getLimitedCodeGenPipelineReason(" and ") << ".\n";
+        delete PTPC;
+        delete MMIWP;
         return 1;
       }
 


        


More information about the llvm-commits mailing list