From: Nick Mathewson Date: Thu, 10 Apr 2014 15:16:42 +0000 (-0400) Subject: On Windows, terminate processes by handle, not pid X-Git-Tag: tor-0.2.5.5-alpha~10^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=34f8723dc784142b30d92bbbdeb37089ae7a3bc5;p=thirdparty%2Ftor.git On Windows, terminate processes by handle, not pid When we create a process yourself with CreateProcess, we get a handle to the process in the PROCESS_INFO output structure. But instead of using that handle, we were manually looking up a _new_ handle based on the process ID, which is a poor idea, since the process ID might refer to a new process later on, but the handle can't. --- diff --git a/src/common/util.c b/src/common/util.c index 0a14101396..f79e72beac 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -3629,13 +3629,7 @@ tor_terminate_process(process_handle_t *process_handle) { #ifdef _WIN32 if (tor_get_exit_code(process_handle, 0, NULL) == PROCESS_EXIT_RUNNING) { - HANDLE handle; - /* If the signal is outside of what GenerateConsoleCtrlEvent can use, - attempt to open and terminate the process. */ - handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, - process_handle->pid.dwProcessId); - if (!handle) - return -1; + HANDLE handle = process_handle->pid.hProcess; if (!TerminateProcess(handle, 0)) return -1;