From: Chetan Toshniwal Date: Wed, 15 Jul 2015 13:24:37 +0000 (+0530) Subject: Fix memory leak in caqueueingthread X-Git-Tag: 1.2.0+RC1~1440 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11a2f8ab760494175ff392cc9917ee8fcfdc594e;p=platform%2Fupstream%2Fiotivity.git Fix memory leak in caqueueingthread free preallocated memory on failure and return CA_MEMORY_ALLOC_FAILED. Change-Id: I9f5b9591b96d9dd0bf96bbaf7e9c5a6407ad831e Signed-off-by: Chetan Toshniwal Reviewed-on: https://gerrit.iotivity.org/gerrit/1671 Reviewed-by: Erich Keane Tested-by: jenkins-iotivity --- diff --git a/resource/csdk/connectivity/src/caqueueingthread.c b/resource/csdk/connectivity/src/caqueueingthread.c index 4b7a511..c410be9 100644 --- a/resource/csdk/connectivity/src/caqueueingthread.c +++ b/resource/csdk/connectivity/src/caqueueingthread.c @@ -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)