[Spice-commits] vdagent/vdagent.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 18 10:48:36 UTC 2018


 vdagent/vdagent.cpp |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

New commits:
commit 7038aa83b393146ceaaa5ada74fdd76beef150ac
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Jul 8 20:48:56 2018 +0100

    vdagent: Stop correctly helper thread
    
    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>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 306bfbd..e577679 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -238,20 +238,27 @@ 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:
+            // handle APC events
+            break;
         case WAIT_TIMEOUT:
         default:
-            vd_printf("WaitForSingleObject(): %lu", wait_ret);
+            vd_printf("WaitForSingleObjectEx(): %lu", wait_ret);
         }
     }
     CloseHandle(desktop_event);
     return 0;
 }
 
+static VOID CALLBACK event_thread_stop_proc(ULONG_PTR)
+{
+}
+
 bool VDAgent::run()
 {
     DWORD session_id;
@@ -333,8 +340,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;
 }
 


More information about the Spice-commits mailing list