From 30fa5223bcf417cfe43a2f0139b54c6e349d3eab Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 8 Jul 2016 02:19:57 -0700 Subject: [PATCH] #4768 Fixed race condition on active client proxy switch --- src/lib/server/Server.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 1f3bf3b2..7e85e811 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -496,6 +496,18 @@ Server::switchScreen(BaseClientProxy* dst, } } + // if already sending clipboard, we need to interupt it, otherwise + // clipboard data could be corrupted on the other side + // interrupt before switch active, as send clipboard uses active + // client proxy, which would cause race condition + if (m_sendClipboardThread != NULL) { + StreamChunker::setClipboardInterrupt(true); + m_sendClipboardThread->wait(); + delete m_sendClipboardThread; + m_sendClipboardThread = NULL; + StreamChunker::setClipboardInterrupt(false); + } + // cut over m_active = dst; @@ -506,15 +518,6 @@ Server::switchScreen(BaseClientProxy* dst, m_active->enter(x, y, m_seqNum, m_primaryClient->getToggleMask(), forScreensaver); - // if already sending clipboard, we need to interupt it, otherwise - // clipboard data could be corrupted on the other side - if (m_sendClipboardThread != NULL) { - StreamChunker::setClipboardInterrupt(true); - m_sendClipboardThread->wait(); - delete m_sendClipboardThread; - m_sendClipboardThread = NULL; - StreamChunker::setClipboardInterrupt(false); - } // send the clipboard data to new active screen m_sendClipboardThread = new Thread(