Skip to content

Commit b84d390

Browse files
committed
Fix child process handle closing
1 parent fdbf532 commit b84d390

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Win32_Interop/Win32_QFork.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct QForkControl {
190190

191191
QForkControl* g_pQForkControl;
192192
HANDLE g_hQForkControlFileMap;
193-
HANDLE g_hForkedProcess;
193+
HANDLE g_hForkedProcess = 0;
194194
DWORD g_systemAllocationGranularity;
195195
int g_ChildExitCode = 0; // For child process
196196

@@ -1030,13 +1030,13 @@ OperationStatus GetForkOperationStatus() {
10301030
return OperationStatus::osFAILED;
10311031
}
10321032

1033-
if (WaitForSingleObject(g_pQForkControl->forkedProcessReady, 0) == WAIT_OBJECT_0) {
1033+
if (g_hForkedProcess && WaitForSingleObject(g_pQForkControl->forkedProcessReady, 0) == WAIT_OBJECT_0) {
10341034
// Verify if the child process is still running
10351035
if (WaitForSingleObject(g_hForkedProcess, 0) == WAIT_OBJECT_0) {
10361036
// The child process is not running, close the handle and report the status
10371037
// setting the operationFailed event
1038-
g_hForkedProcess = 0;
10391038
CloseHandle(g_hForkedProcess);
1039+
g_hForkedProcess = 0;
10401040
if (g_pQForkControl->operationFailed != NULL) {
10411041
SetEvent(g_pQForkControl->operationFailed);
10421042
}
@@ -1060,8 +1060,8 @@ BOOL AbortForkOperation()
10601060
system_category(),
10611061
"EndForkOperation: Killing forked process failed.");
10621062
}
1063-
g_hForkedProcess = 0;
10641063
CloseHandle(g_hForkedProcess);
1064+
g_hForkedProcess = 0;
10651065
}
10661066

10671067
return EndForkOperation(NULL);
@@ -1162,7 +1162,7 @@ BOOL EndForkOperation(int * pExitCode) {
11621162
}
11631163

11641164
if (pExitCode != NULL) {
1165-
GetExitCodeProcess(g_hForkedProcess, (DWORD*)pExitCode);
1165+
GetExitCodeProcess(g_hForkedProcess, (DWORD*)pExitCode);
11661166
}
11671167

11681168
CloseHandle(g_hForkedProcess);

0 commit comments

Comments
 (0)