Summary
In compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp, the function LLVMRustWriteOutputFile only calls LLVMDisposePassManager(PMR) on the success path. Both error-return paths leak the pass manager.
Location
compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp, lines 478 and 489
Bug
extern "C" LLVMRustResult
LLVMRustWriteOutputFile(..., LLVMPassManagerRef PMR, ...) {
...
if (ErrorInfo != "") {
LLVMRustSetLastError(ErrorInfo.c_str());
return LLVMRustResult::Failure; // PMR leaked (line 478)
}
...
return LLVMRustResult::Failure; // PMR leaked (line 489, also dead code per #493)
...
LLVMDisposePassManager(PMR); // only reached on success (line 502)
return LLVMRustResult::Success;
}
Impact
In practice, line 478 fires when the primary output file cannot be opened, which typically causes compilation to abort shortly after. Line 489 is dead code (see issue #493). So this leak is mostly theoretical.
Fix
Call LLVMDisposePassManager(PMR) before each error return, or restructure to use RAII/goto cleanup.
Summary
In
compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp, the functionLLVMRustWriteOutputFileonly callsLLVMDisposePassManager(PMR)on the success path. Both error-return paths leak the pass manager.Location
compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp, lines 478 and 489Bug
Impact
In practice, line 478 fires when the primary output file cannot be opened, which typically causes compilation to abort shortly after. Line 489 is dead code (see issue #493). So this leak is mostly theoretical.
Fix
Call
LLVMDisposePassManager(PMR)before each error return, or restructure to use RAII/goto cleanup.