Skip to content

Commit

Permalink
Add delete to fix resource leak in llc.cpp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
XinWang10 committed Apr 12, 2023
1 parent 07fef17 commit 3657e77
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion llvm/tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3657e77

Please sign in to comment.