diff --git a/main/forwarder/source/main.cpp b/main/forwarder/source/main.cpp index b5f6bf349..97781f5cb 100644 --- a/main/forwarder/source/main.cpp +++ b/main/forwarder/source/main.cpp @@ -126,17 +126,18 @@ int launchExecutable() { // Wait for the child process to exit ::WaitForSingleObject(pi.hProcess, INFINITE); - // Clean up - ::CloseHandle(pi.hProcess); - ::CloseHandle(pi.hThread); - ::CloseHandle(hChildStdoutRead); - + // Get the exit code of the child process DWORD exitCode = 0; - if (::GetExitCodeProcess(pi.hProcess, &exitCode)) { - return static_cast(exitCode); - } else { - return EXIT_FAILURE; + if (!::GetExitCodeProcess(pi.hProcess, &exitCode)) { + exitCode = EXIT_FAILURE; } + + // Clean up + ::CloseHandle(pi.hProcess); + ::CloseHandle(pi.hThread); + ::CloseHandle(hChildStdoutRead); + + return static_cast(exitCode); } int main() {