Fix potential thread cancel issue 07/213707/2
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 10 Sep 2019 09:04:23 +0000 (18:04 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 11 Sep 2019 06:15:40 +0000 (15:15 +0900)
Change-Id: Id6f37948bfa6b7c3dd61cf2fdc9a585b1f3ec35e

agent/download-agent-dl-mgr.c
agent/download-agent-http-mgr.c
packaging/download-provider.spec
provider/download-provider-client.c
provider/download-provider-queue-manager.c

index 2da7d99..0bce375 100755 (executable)
 #include "download-agent-dl-info.h"
 #include "download-agent-http-mgr.h"
 
-void __thread_clean_up_handler_for_start_download(void *arg)
-{
-       DA_LOGI("cleanup for thread id[%lu]", pthread_self());
-}
-
 da_ret_t __download_content(da_info_t *da_info)
 {
        da_ret_t ret = DA_RESULT_OK;
@@ -42,7 +37,6 @@ da_ret_t __download_content(da_info_t *da_info)
        return ret;
 }
 
-
 static void *__thread_start_download(void *data)
 {
        da_info_t *da_info = DA_NULL;
@@ -59,10 +53,8 @@ static void *__thread_start_download(void *data)
        NULL_CHECK_RET_OPT(req_info, DA_NULL);
 
        da_id = da_info->da_id;
-       pthread_cleanup_push(__thread_clean_up_handler_for_start_download, DA_NULL);
        __download_content(da_info);
        destroy_da_info(da_id);
-       pthread_cleanup_pop(0);
        DA_LOGI("=====EXIT thread : da_id[%d]=====", da_id);
        pthread_exit((void *)DA_NULL);
        return DA_NULL;
index 56228db..ad410b2 100755 (executable)
@@ -647,7 +647,6 @@ da_ret_t request_to_cancel_http_download(da_info_t *da_info)
        da_ret_t ret = DA_RESULT_OK;
        http_info_t *http_info = DA_NULL;
        http_state_t http_state = 0;
-       int status;
        int mutex_ret = 0;
 
        DA_LOGV("");
@@ -666,16 +665,6 @@ da_ret_t request_to_cancel_http_download(da_info_t *da_info)
                DA_MUTEX_LOCK(&(http_info->mutex_state));
                http_info->state = HTTP_STATE_CANCELED;
                DA_MUTEX_UNLOCK(&(http_info->mutex_state));
-               if (da_info->thread_id > 0) {
-                       if (pthread_cancel(da_info->thread_id) != 0) {
-                               DA_LOGE("Fail to cancel thread id[%lu]",
-                                               da_info->thread_id);
-                               pthread_join(da_info->thread_id, (void **)&status);
-                       } else {
-                               DA_LOGI("====Exit thread with cancel:da_id[%d]===",
-                                               da_info->da_id);
-                       }
-               }
                break;
        case HTTP_STATE_WAIT_FOR_NET_ERR:
                DA_MUTEX_LOCK(&(http_info->mutex_state));
index 197f060..412f09c 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       download-provider
 Summary:    Download the contents in background
-Version:    2.1.115
+Version:    2.1.116
 Release:    0
 Group:      Development/Libraries
 License:    Apache-2.0
index ff6cd3e..6b73939 100755 (executable)
@@ -1973,7 +1973,6 @@ void *dp_client_request_thread(void *arg)
 
        while (slot != NULL && client_sock >= 0 &&
                        client_sock == slot->client.channel) {
-
                memset(&timeout, 0x00, sizeof(struct timeval));
                timeout.tv_sec = DP_CARE_CLIENT_REQUEST_INTERVAL;
                FD_ZERO(&imask);
@@ -1995,9 +1994,9 @@ void *dp_client_request_thread(void *arg)
                }
                if (FD_ISSET(client_sock, &imask) > 0) {
 
+                       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
                        CLIENT_MUTEX_LOCK(&slot->mutex);
 
-                       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
                        client->access_time = (int)time(NULL);
 
                        errorcode = DP_ERROR_NONE;
@@ -2033,8 +2032,8 @@ void *dp_client_request_thread(void *arg)
                        }
                        free(ipc_info);
 
-                       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
                        CLIENT_MUTEX_UNLOCK(&slot->mutex);
+                       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 
                        if (errorcode == DP_ERROR_IO_ERROR ||
                                        errorcode == DP_ERROR_OUT_OF_MEMORY ||
index 038ff52..a2d05eb 100644 (file)
@@ -259,7 +259,6 @@ static void *__dp_queue_manager(void *arg)
                CLIENT_MUTEX_LOCK(&g_dp_queue_manager_mutex);
                pthread_cond_timedwait(&g_dp_queue_manager_cond, &g_dp_queue_manager_mutex, &ts);
                CLIENT_MUTEX_UNLOCK(&g_dp_queue_manager_mutex);
-
        } while (g_dp_queue_manager_tid > 0);
 
        TRACE_DEBUG("queue-manager's working is done");
@@ -310,7 +309,6 @@ void dp_queue_manager_kill()
                g_dp_queue_manager_tid = 0;
                pthread_cond_signal(&g_dp_queue_manager_cond);
                CLIENT_MUTEX_UNLOCK(&g_dp_queue_manager_mutex);
-               pthread_cancel(tid);
                pthread_join(tid, (void **)&status);
        }
 }