Skip to content

Commit b7288de

Browse files
lunacdhebasto
authored andcommitted
subprocess: Proper implementation of wait() on Windows
This commit makes sure: 1. WaitForSingleObject returns with expected code before proceeding. 2. Process handle is properly closed. Github-Pull: arun11299/cpp-subprocess#116 Rebased-From: 625a8775791e62736f20f3fa3e6cc4f1b24aa89a
1 parent 7423214 commit b7288de

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/util/subprocess.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,11 +1061,18 @@ inline int Popen::wait() noexcept(false)
10611061
#ifdef __USING_WINDOWS__
10621062
int ret = WaitForSingleObject(process_handle_, INFINITE);
10631063

1064+
// WaitForSingleObject with INFINITE should only return when process has signaled
1065+
if (ret != WAIT_OBJECT_0) {
1066+
throw OSError("Unexpected return code from WaitForSingleObject", 0);
1067+
}
1068+
10641069
DWORD dretcode_;
10651070

10661071
if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_))
10671072
throw OSError("Failed during call to GetExitCodeProcess", 0);
10681073

1074+
CloseHandle(process_handle_);
1075+
10691076
return (int)dretcode_;
10701077
#else
10711078
int ret, status;

0 commit comments

Comments
 (0)