From 5d8046c67a4e3090d89440143560b121c948e8c5 Mon Sep 17 00:00:00 2001 From: Kush Date: Mon, 2 Mar 2020 18:16:29 +0530 Subject: [CONPRO-1558] Adding check for tasks already freed through ca_thread_pool_free https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/667 (cherry-picked from 2977211f5c3927ac9613688e37cc4cd06e44f1d6) Change-Id: Ie7dd756317d1cab004861c7b85aa9822e94b4b0d Signed-off-by: Kush Signed-off-by: DoHyun Pyun --- resource/csdk/connectivity/common/src/cathreadpool_pthreads.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'resource') diff --git a/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c b/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c index 7bb19dd54..f1bb5c25a 100644 --- a/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c +++ b/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c @@ -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 *) -- cgit v1.2.3