@@ -178,7 +178,6 @@ std::string GetCommandLine(const std::vector<std::string> &arguments) {
178178
179179int RunSubProcess (const std::vector<std::string> &args,
180180 std::ostream *stderr_stream, bool stdout_to_stderr) {
181- PROCESS_INFORMATION piProcess = {0 };
182181 std::error_code ec;
183182 std::unique_ptr<WindowsIORedirector> redirector =
184183 WindowsIORedirector::Create (stdout_to_stderr, ec);
@@ -188,6 +187,7 @@ int RunSubProcess(const std::vector<std::string> &args,
188187 return 254 ;
189188 }
190189
190+ PROCESS_INFORMATION piProcess = {0 };
191191 if (!CreateProcessA (NULL , GetCommandLine (args).data (), nullptr , nullptr , TRUE ,
192192 0 , nullptr , nullptr , &redirector->siStartInfo ,
193193 &piProcess)) {
@@ -196,13 +196,15 @@ int RunSubProcess(const std::vector<std::string> &args,
196196 << " )\n " ;
197197 return dwLastError;
198198 }
199+
200+ CloseHandle (piProcess.hThread );
201+
199202 redirector->ConsumeAllSubprocessOutput (stderr_stream);
200203
201204 if (WaitForSingleObject (piProcess.hProcess , INFINITE) == WAIT_FAILED) {
202205 DWORD dwLastError = GetLastError ();
203206 (*stderr_stream) << " wait for process failure (error " << dwLastError
204207 << " )\n " ;
205- CloseHandle (piProcess.hThread );
206208 CloseHandle (piProcess.hProcess );
207209 return dwLastError;
208210 }
@@ -212,12 +214,10 @@ int RunSubProcess(const std::vector<std::string> &args,
212214 DWORD dwLastError = GetLastError ();
213215 (*stderr_stream) << " unable to get exit code (error " << dwLastError
214216 << " )\n " ;
215- CloseHandle (piProcess.hThread );
216217 CloseHandle (piProcess.hProcess );
217218 return dwLastError;
218219 }
219220
220- CloseHandle (piProcess.hThread );
221221 CloseHandle (piProcess.hProcess );
222222 return dwExitCode;
223223}
0 commit comments