[CONPRO-1558] Adding check for tasks already freed through ca_thread_pool_free 99/229399/1
authorKush <kush.agrawal@samsung.com>
Mon, 2 Mar 2020 12:46:29 +0000 (18:16 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Wed, 1 Apr 2020 01:32:04 +0000 (10:32 +0900)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/667
(cherry-picked from 2977211f5c3927ac9613688e37cc4cd06e44f1d6)

Change-Id: Ie7dd756317d1cab004861c7b85aa9822e94b4b0d
Signed-off-by: Kush <kush.agrawal@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/connectivity/common/src/cathreadpool_pthreads.c

index 7bb19dd..f1bb5c2 100644 (file)
@@ -50,6 +50,7 @@ typedef struct ca_thread_pool_details_t
 {
     u_arraylist_t* threads_list;
     oc_mutex list_lock;
+    bool isFree;
 } ca_thread_pool_details_t;
 
 /**
@@ -135,6 +136,8 @@ CAResult_t ca_thread_pool_init(int32_t num_of_threads, ca_thread_pool_t *thread_
         goto exit;
     }
 
+    (*thread_pool)->details->isFree = false;
+
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 
@@ -232,6 +235,11 @@ CAResult_t ca_thread_pool_remove_task(ca_thread_pool_t thread_pool, uint32_t tas
         return CA_STATUS_FAILED;
     }
 
+    if(thread_pool->details->isFree){
+        OIC_LOG(INFO, TAG, "thread pool tasks already freed");
+        return CA_STATUS_OK;
+    }
+
     oc_mutex_lock(thread_pool->details->list_lock);
     for (uint32_t i = 0; i < u_arraylist_length(thread_pool->details->threads_list); ++i)
     {
@@ -272,6 +280,8 @@ void ca_thread_pool_free(ca_thread_pool_t thread_pool)
 
     oc_mutex_lock(thread_pool->details->list_lock);
 
+    thread_pool->details->isFree = true;
+
     for (uint32_t i = 0; i < u_arraylist_length(thread_pool->details->threads_list); ++i)
     {
         ca_thread_pool_thread_info_t *threadInfo = (ca_thread_pool_thread_info_t *)