Fix memory leak in caqueueingthread
authorChetan Toshniwal <c.toshniwal@samsung.com>
Wed, 15 Jul 2015 13:24:37 +0000 (18:54 +0530)
committerErich Keane <erich.keane@intel.com>
Fri, 17 Jul 2015 05:57:28 +0000 (05:57 +0000)
free preallocated memory on failure and return CA_MEMORY_ALLOC_FAILED.

Change-Id: I9f5b9591b96d9dd0bf96bbaf7e9c5a6407ad831e
Signed-off-by: Chetan Toshniwal <c.toshniwal@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1671
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/connectivity/src/caqueueingthread.c

index 4b7a511..c410be9 100644 (file)
@@ -146,8 +146,28 @@ CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, ca_thread_pool
     thread->isStop = true;
     thread->threadTask = task;
     thread->destroy = destroy;
+    if(NULL == thread->dataQueue || NULL == thread->threadMutex || NULL == thread->threadCond)
+        goto ERROR_MEM_FAILURE;
 
     return CA_STATUS_OK;
+    ERROR_MEM_FAILURE:
+    if(thread->dataQueue)
+    {
+        u_queue_delete(thread->dataQueue);
+        thread->dataQueue = NULL;
+    }
+    if(thread->threadMutex)
+    {
+        ca_mutex_free(thread->threadMutex);
+        thread->threadMutex = NULL;
+    }
+    if(thread->threadCond)
+    {
+        ca_cond_free(thread->threadCond);
+        thread->threadCond = NULL;
+    }
+    return CA_MEMORY_ALLOC_FAILED;
+
 }
 
 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread)