From 0d310a8464084f1bf37bf574e81df033f0ab0960 Mon Sep 17 00:00:00 2001 From: Nye Liu Date: Thu, 3 Sep 2015 12:09:35 -0700 Subject: [PATCH] Properly lock condVar, add timeout condition to prevent infinite loop when waiting for fillClipboard() to finish --- src/lib/client/Client.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 62dbb22a..ac8191ae 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -283,8 +283,16 @@ Client::leave() &Client::sendClipboardThread, NULL)); // Bug #4735 - we can't leave() until fillClipboard()s all finish - while (!m_condData) - m_condVar->wait(); + Stopwatch timer(true); + m_mutex->lock(); + while (!m_condData) { + m_condVar->wait(timer, 0.5); + if (timer.getTime()>0.5) { + LOG((CLOG_DEBUG "timed out waiting for clipboard fill")); + break; + } + } + m_mutex->unlock(); m_screen->leave(); @@ -791,8 +799,10 @@ Client::sendClipboardThread(void * data) } // signal that fill is done + m_mutex->lock(); m_condData = true; m_condVar->signal(); + m_mutex->unlock(); // send clipboards that we own and that have changed for (ClipboardID id = 0; id < kClipboardEnd; ++id) {