[Spice-devel] [PATCH vdagent-win 3/6] vdservice: clean agent proc handle in kill_agent()

Alon Levy alevy at redhat.com
Sun Jul 24 04:11:36 PDT 2011


On Sun, Jul 24, 2011 at 01:48:15PM +0300, Arnon Gilboa wrote:
> prevent usage of a dead proc handle in the WaitFor()

Is this usage in fill_agent_event? can you make a note of that in the
commit message?

Otherwise ACK.

> ---
>  vdservice/vdservice.cpp |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
> index 7ca9db8..f61c318 100644
> --- a/vdservice/vdservice.cpp
> +++ b/vdservice/vdservice.cpp
> @@ -898,21 +898,24 @@ bool VDService::kill_agent()
>  {
>      DWORD exit_code = 0;
>      DWORD wait_ret;
> +    HANDLE proc_handle;
>      bool ret = true;
>  
>      if (!_agent_alive) {
>          return true;
>      }
>      _agent_alive = false;
> +    proc_handle = _agent_proc_info.hProcess;
> +    _agent_proc_info.hProcess = 0;
>      if (_pipe_connected) {
>          _pipe_connected = false;
>          DisconnectNamedPipe(_pipe_state.pipe);
>      }
> -    if (GetProcessId(_agent_proc_info.hProcess)) {
> -        wait_ret = WaitForSingleObject(_agent_proc_info.hProcess, 3000);
> +    if (GetProcessId(proc_handle)) {
> +        wait_ret = WaitForSingleObject(proc_handle, 3000);
>          switch (wait_ret) {
>          case WAIT_OBJECT_0:
> -            if (GetExitCodeProcess(_agent_proc_info.hProcess, &exit_code)) {
> +            if (GetExitCodeProcess(proc_handle, &exit_code)) {
>                  vd_printf("vdagent exit code %u", exit_code);
>              } else if (exit_code == STILL_ACTIVE) {
>                  vd_printf("Failed killing vdagent");
> @@ -931,7 +934,7 @@ bool VDService::kill_agent()
>              break;
>          }
>      }
> -    CloseHandle(_agent_proc_info.hProcess);
> +    CloseHandle(proc_handle);
>      CloseHandle(_agent_proc_info.hThread);
>      ZeroMemory(&_agent_proc_info, sizeof(_agent_proc_info));
>      return ret;
> -- 
> 1.7.4.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list