You've already forked fido2-manage.cpp
mirror of
https://github.com/token2/fido2-manage.cpp.git
synced 2026-06-22 14:42:52 -07:00
Merge pull request #18 from allamiro/bugfix/issue-6-pipe-handle-leak-createprocess-fail
Fix hPipeWrite handle leak when CreateProcess fails
This commit is contained in:
+10
-6
@@ -84,12 +84,14 @@ std::vector<std::wstring> RunCommandAndGetOutput(const std::wstring& command) {
|
||||
|
||||
PROCESS_INFORMATION pi = { 0 };
|
||||
|
||||
if (CreateProcess(
|
||||
bool processCreated = CreateProcess(
|
||||
NULL,
|
||||
const_cast<LPWSTR>(command.c_str()),
|
||||
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
|
||||
CloseHandle(hPipeWrite);
|
||||
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) != 0;
|
||||
|
||||
CloseHandle(hPipeWrite);
|
||||
|
||||
if (processCreated) {
|
||||
char buffer[1024];
|
||||
DWORD bytesRead;
|
||||
while (ReadFile(hPipeRead, buffer, sizeof(buffer) - 1, &bytesRead, NULL) && bytesRead > 0) {
|
||||
@@ -637,12 +639,14 @@ std::vector<std::wstring> RunCommandAndGetOutputWithTimeout(const std::wstring&
|
||||
|
||||
PROCESS_INFORMATION pi = { 0 };
|
||||
|
||||
if (CreateProcess(
|
||||
bool processCreated = CreateProcess(
|
||||
NULL,
|
||||
const_cast<LPWSTR>(command.c_str()),
|
||||
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
|
||||
CloseHandle(hPipeWrite);
|
||||
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi) != 0;
|
||||
|
||||
CloseHandle(hPipeWrite);
|
||||
|
||||
if (processCreated) {
|
||||
// Wait for the process to finish or timeout
|
||||
DWORD waitResult = WaitForSingleObject(pi.hProcess, timeoutMs);
|
||||
if (waitResult == WAIT_TIMEOUT) {
|
||||
|
||||
Reference in New Issue
Block a user