cec: check whether m_port isn't NULL in ReadFromDevice
[deb_libcec.git] / src / lib / AdapterCommunication.cpp
index 266842f7f64927d966842aea1172988c619a95dd..d56ee168b642df7d2ab173677569c0271222ecdb 100644 (file)
@@ -33,7 +33,7 @@
 #include "AdapterCommunication.h"
 
 #include "LibCEC.h"
-#include "libPlatform/serialport.h"
+#include "platform/serialport.h"
 #include "util/StdString.h"
 
 using namespace std;
@@ -52,7 +52,9 @@ CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
 
 CAdapterCommunication::~CAdapterCommunication(void)
 {
+  StopThread();
   m_port->Close();
+  delete m_port;
   m_port = NULL;
 }
 
@@ -110,11 +112,10 @@ void *CAdapterCommunication::Process(void)
       break;
     }
 
-    CCondition::Sleep(50);
+    if (!m_bStop)
+      CCondition::Sleep(50);
   }
 
-  m_controller->AddLog(CEC_LOG_DEBUG, "reader thread terminated");
-
   CLockObject lock(&m_commMutex);
   m_bStarted = false;
   return NULL;
@@ -124,6 +125,9 @@ bool CAdapterCommunication::ReadFromDevice(int iTimeout)
 {
   uint8_t buff[1024];
   CLockObject lock(&m_commMutex);
+  if (!m_port)
+    return false;
+
   int iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
   lock.Leave();
   if (iBytesRead < 0)