diff --git a/src/util/subprocess.h b/src/util/subprocess.h index 67d0a59ed10..29f6e8ffa7e 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -1055,11 +1055,18 @@ inline int Popen::wait() noexcept(false) #ifdef __USING_WINDOWS__ int ret = WaitForSingleObject(process_handle_, INFINITE); + // WaitForSingleObject with INFINITE should only return when process has signaled + if (ret != WAIT_OBJECT_0) { + throw OSError("Unexpected return code from WaitForSingleObject", 0); + } + DWORD dretcode_; if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_)) throw OSError("Failed during call to GetExitCodeProcess", 0); + CloseHandle(process_handle_); + return (int)dretcode_; #else int ret, status;