[llvm] [llvm-objdump] Fix mcpuHelp() memory leak (PR #172525)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 16 09:46:30 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Ruoyu Qiu (cabbaken)
<details>
<summary>Changes</summary>
The call to `DummyTarget->createMCSubtargetInfo` within `mcpuHelp()` returns a pointer that is not subsequently freed, leading to a memory leak.
Use std::unique_ptr to ensure the memory is released automatically.
---
Full diff: https://github.com/llvm/llvm-project/pull/172525.diff
1 Files Affected:
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+2-1)
``````````diff
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 97032eca5f2d1..7fd0eed151b17 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3581,7 +3581,8 @@ static void mcpuHelp() {
if (!DummyTarget)
reportCmdLineError(ErrMessage);
// We need to access the Help() through the corresponding MCSubtargetInfo.
- DummyTarget->createMCSubtargetInfo(TheTriple, "help", "");
+ std::unique_ptr<MCSubtargetInfo> MSI(
+ DummyTarget->createMCSubtargetInfo(TheTriple.str(), "help", ""));
}
static void parseOtoolOptions(const llvm::opt::InputArgList &InputArgs) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/172525
More information about the llvm-commits
mailing list