cec: fix segfault on exit
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 4 Oct 2011 18:31:56 +0000 (20:31 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 4 Oct 2011 18:31:56 +0000 (20:31 +0200)
src/lib/AdapterCommunication.cpp
src/lib/CECProcessor.cpp
src/lib/LibCEC.cpp
src/lib/platform/threads.cpp

index a7466b70a1013c11fb9e231b1e0eb130434f1134..3a403068811a0dfee97d077bbf62f70f057f735a 100644 (file)
@@ -110,7 +110,8 @@ void *CAdapterCommunication::Process(void)
       break;
     }
 
-    CCondition::Sleep(50);
+    if (!m_bStop)
+      CCondition::Sleep(50);
   }
 
   m_controller->AddLog(CEC_LOG_DEBUG, "reader thread terminated");
index 127155a95195da75004f01213761ffd8dce62195..4a276ee760b7cc1b1b406e127a3a8e6fc37d401c 100644 (file)
@@ -89,14 +89,16 @@ void *CCECProcessor::Process(void)
         bParseFrame = ParseMessage(msg);
     }
 
-    if (bParseFrame)
+    if (!m_bStop && bParseFrame)
       ParseCurrentFrame();
 
-    m_controller->CheckKeypressTimeout();
-    CCondition::Sleep(50);
+    if (!m_bStop)
+    {
+      m_controller->CheckKeypressTimeout();
+      CCondition::Sleep(50);
+    }
   }
 
-  m_controller->AddLog(CEC_LOG_DEBUG, "processor thread terminated");
   return NULL;
 }
 
index 19f34ea3c8a468bad81af5c97f7a67138b91686b..87759c153926d5343a7e8cb0be3f12e76e1e7d97 100644 (file)
@@ -87,9 +87,17 @@ bool CLibCEC::Open(const char *strPort, int iTimeoutMs /* = 10000 */)
 void CLibCEC::Close(void)
 {
   if (m_cec)
+  {
     m_cec->StopThread();
+    delete m_cec;
+    m_cec = NULL;
+  }
   if (m_comm)
+  {
     m_comm->Close();
+    delete m_comm;
+    m_comm = NULL;
+  }
 }
 
 int CLibCEC::FindAdapters(std::vector<cec_adapter> &deviceList, const char *strDevicePath /* = NULL */)
index 8933a21baf0881a06ea2ed5eb07768fbf28c7dfa..7c5b6ce4ed716de8cda00689de685482fca57eda 100644 (file)
@@ -120,7 +120,7 @@ void CCondition::Sleep(int iTimeout)
   CCondition w;
   CMutex m;
   CLockObject lock(&m);
-  w.Wait(&m, iTimeout);
+  w.Wait(&m, int64_t(iTimeout));
 }
 
 CThread::CThread(void) :