[CONPRO-1442] Fix crash in cpp wrapper.
[platform/upstream/iotivity.git] / resource / src / InProcClientWrapper.cpp
index 0dfc3b6..132d082 100755 (executable)
@@ -98,30 +98,29 @@ namespace OC
     {
         OIC_LOG(INFO, TAG, "stop ocplatform");
 
-        if (m_threadRun && m_listeningThread.joinable())
+        // only stop if we are the ones who actually called 'start'.  We are counting
+        // on the server to do the stop.
+        if (m_cfg.mode == ModeType::Client)
         {
-            m_threadRun = false;
-#ifdef WITH_PROCESS_EVENT
-            if (m_processEvent)
+            if (m_threadRun && m_listeningThread.joinable())
             {
-                oc_event_signal(m_processEvent);
-            }
+                m_threadRun = false;
+#ifdef WITH_PROCESS_EVENT
+                if (m_processEvent)
+                {
+                    oc_event_signal(m_processEvent);
+                }
 #endif
-            m_listeningThread.join();
-        }
+                m_listeningThread.join();
+            }
 
 #ifdef WITH_PROCESS_EVENT
-        if (m_processEvent)
-        {
-            oc_event_free(m_processEvent);
-            m_processEvent = NULL;
-        }
+            if (m_processEvent)
+            {
+                oc_event_free(m_processEvent);
+                m_processEvent = NULL;
+            }
 #endif
-
-        // only stop if we are the ones who actually called 'start'.  We are counting
-        // on the server to do the stop.
-        if (m_cfg.mode == ModeType::Client)
-        {
             OCStackResult result = OCStop();
 
             if (OC_STACK_OK != result)