From: hyuna0213.jo Date: Tue, 29 Nov 2016 08:08:38 +0000 (+0900) Subject: Add pthread_join() in case of failure of ca_thread_pool_add_task() X-Git-Tag: 1.2.1~28 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=796e5b2aa38b4c808deb8f9d264faba4b5b27f1e;p=platform%2Fupstream%2Fiotivity.git Add pthread_join() in case of failure of ca_thread_pool_add_task() In case of failure, we should call pthread_join() to free memory or other resources that were allocated to the target thread. Change-Id: Iabcb25751301b8cdb95565355cc0b6d3cffafc1d Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/14889 Tested-by: jenkins-iotivity Reviewed-by: Jaehong Jo Reviewed-by: jihwan seo Reviewed-by: Ziran Sun --- diff --git a/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c b/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c index 3865df6dc..7157005db 100644 --- a/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c +++ b/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c @@ -175,9 +175,23 @@ CAResult_t ca_thread_pool_add_task(ca_thread_pool_t thread_pool, ca_thread_func bool addResult = u_arraylist_add(thread_pool->details->threads_list, (void*)threadHandle); ca_mutex_unlock(thread_pool->details->list_lock); - if(!addResult) + if (!addResult) { OIC_LOG_V(ERROR, TAG, "Arraylist Add failed, may not be properly joined: %d", addResult); +#if defined(_WIN32) + DWORD joinres = WaitForSingleObject(threadHandle, INFINITE); + if (WAIT_OBJECT_0 != joinres) + { + OIC_LOG_V(ERROR, TAG, "Failed to join thread with error %d", joinres); + } + CloseHandle(threadHandle); +#else + int joinres = pthread_join(threadHandle, NULL); + if (0 != joinres) + { + OIC_LOG_V(ERROR, TAG, "Failed to join thread with error %d", joinres); + } +#endif return CA_STATUS_FAILED; }