[Spice-devel] [vdagent-win PATCH v5 6/6] vdagent: Stop correctly helper thread
Christophe Fergeau
cfergeau at redhat.com
Wed Jul 18 09:32:55 UTC 2018
On Mon, Jul 09, 2018 at 09:51:44AM +0100, Frediano Ziglio wrote:
> The thread launched to detect desktop switches events is not stopped
> correctly causing potentially dandling pointers.
> Queue a APC to make the loop exit and wait for thread termination
> from the main thread.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> vdagent/vdagent.cpp | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
> index e0923be..0321d85 100644
> --- a/vdagent/vdagent.cpp
> +++ b/vdagent/vdagent.cpp
> @@ -240,11 +240,13 @@ DWORD WINAPI VDAgent::event_thread_proc(LPVOID param)
> return 1;
> }
> while (agent->_running) {
> - DWORD wait_ret = WaitForSingleObject(desktop_event, INFINITE);
> + DWORD wait_ret = WaitForSingleObjectEx(desktop_event, INFINITE, TRUE);
> switch (wait_ret) {
> case WAIT_OBJECT_0:
> agent->set_control_event(CONTROL_DESKTOP_SWITCH);
> break;
> + case WAIT_IO_COMPLETION:
> + break;
Maybe add a comment here that we get WAIT_IO_COMPLETION when receiving
an APC? Or is this obvious to someone familiar with windows?
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
even though we are exiting anyway, so I'd assume this is why it's not
cleaned up properly?
Christophe
> case WAIT_TIMEOUT:
> default:
> vd_printf("WaitForSingleObject(): %lu", wait_ret);
> @@ -254,6 +256,10 @@ DWORD WINAPI VDAgent::event_thread_proc(LPVOID param)
> return 0;
> }
>
> +static VOID CALLBACK event_thread_stop_proc(ULONG_PTR)
> +{
> +}
> +
> bool VDAgent::run()
> {
> DWORD session_id;
> @@ -335,8 +341,12 @@ bool VDAgent::run()
> set_clipboard_owner(owner_none);
> }
> }
> - vd_printf("Agent stopped");
> + if (!QueueUserAPC(event_thread_stop_proc, event_thread, 0)) {
> + TerminateThread(event_thread, 0);
> + }
> + WaitForSingleObject(event_thread, INFINITE);
> CloseHandle(event_thread);
> + vd_printf("Agent stopped");
> return true;
> }
>
> --
> 2.17.1
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180718/60f78996/attachment.sig>
More information about the Spice-devel
mailing list