Merge bitcoin/bitcoin#36581: subprocess: fix command line memory leak on Windows
What changed, and why it matters
This commit fixes a small memory leak in Bitcoin Core on Windows. When starting an external signer program, the code previously copied the command string into a freshly allocated buffer but never freed it. The fix passes the string's own buffer directly to Windows, eliminating both the copy and the leak. The leak only occurs when an optional external signer is configured, and each leak is tiny (just the command string), so the practical security impact is very low.
No urgent action needed beyond applying the patch. Operators using external signers on Windows should upgrade in due course; the leak is small and slow. No workaround is required.
Security signals we found
Memory leak in Windows-only subprocess creation path
Reachable only when external signer command is configured
No memory corruption, use-after-free, or command-injection vector present
Fix removes unnecessary heap allocation and const-cast workaround
Evidence from the diff
In src/util/subprocess.h, Popen::execute_process() on Windows previously allocated command_line.size()+1 bytes with new char[], copied the command line into it, and passed that buffer to CreateProcessA, but never delete[]’d it. Since C++17, std::string::data() returns a writable pointer, so the patch removes the heap allocation and strcpy_s and passes command_line.data() directly. This is a straightforward resource-cleanup bug, not a memory corruption or injection vulnerability. It is reachable only when -signer=
Changed components
src/util/subprocess.hWindows external signer subprocess spawningInspect captured patch +1 / −4
### src/util/subprocess.h
@@ -1096,9 +1096,6 @@ inline void Popen::execute_process() noexcept(false)
util::quote_argument(argument, command_line, /*force=*/false);
}
- // CreateProcessA can modify szCmdLine so we allocate needed memory
- char *szCmdline = new char[command_line.size() + 1];
- strcpy_s(szCmdline, command_line.size() + 1, command_line.c_str());
PROCESS_INFORMATION piProcInfo;
STARTUPINFOA siStartInfo;
BOOL bSuccess = FALSE;
@@ -1121,7 +1118,7 @@ inline void Popen::execute_process() noexcept(false)
// Create the child process.
bSuccess = CreateProcessA(NULL,
- szCmdline, // command line
+ command_line.data(), // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inheritedWhy this scored 24/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.