Fixed Thread-unsafe code in caqueueingthread.c
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Thu, 12 Jan 2017 04:01:33 +0000 (13:01 +0900)
committerMike Fenelon <mike.fenelon@microsoft.com>
Fri, 13 Jan 2017 18:39:10 +0000 (18:39 +0000)
mutex should be destroyed after deleting data queue.

Change-Id: I191d9519da47421d0e296d02cedd6af5eb757bdd
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16337
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Mike Fenelon <mike.fenelon@microsoft.com>
resource/csdk/connectivity/src/caqueueingthread.c

index 22ae5d8..d5a67dd 100644 (file)
@@ -246,9 +246,8 @@ CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread)
 
     OIC_LOG(DEBUG, TAG, "thread destroy..");
 
-    oc_mutex_free(thread->threadMutex);
-    thread->threadMutex = NULL;
-    oc_cond_free(thread->threadCond);
+    // mutex lock
+    oc_mutex_lock(thread->threadMutex);
 
     // remove all remained list data.
     while (u_queue_get_size(thread->dataQueue) > 0)
@@ -275,6 +274,13 @@ CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread)
     u_queue_delete(thread->dataQueue);
     thread->dataQueue = NULL;
 
+    // mutex unlock
+    oc_mutex_unlock(thread->threadMutex);
+
+    oc_mutex_free(thread->threadMutex);
+    thread->threadMutex = NULL;
+    oc_cond_free(thread->threadCond);
+
     return CA_STATUS_OK;
 }