[Bug fix] Fixed timer function to prevent crash 01/90501/4 accepted/tizen/3.0/common/20161114.105211 accepted/tizen/3.0/mobile/20161015.032639 accepted/tizen/3.0/wearable/20161015.081846 accepted/tizen/common/20161006.153853 accepted/tizen/mobile/20161006.232624 accepted/tizen/wearable/20161006.232641 submit/tizen/20161006.085834 submit/tizen_3.0_common/20161104.104000 submit/tizen_3.0_mobile/20161015.000001 submit/tizen_3.0_wearable/20161015.000001
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 6 Oct 2016 08:08:11 +0000 (17:08 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 6 Oct 2016 08:12:02 +0000 (17:12 +0900)
Change-Id: I88637cb6a891b92697f25b6033875cae9daec6e8
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-http.spec
src/http_session.c
src/http_transaction.c

index 0cb39d2..f35dbbe 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.12
+Version:       0.0.13
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index af38228..74bac8c 100644 (file)
@@ -70,7 +70,8 @@ void _check_curl_multi_status(gpointer user_data)
                                                http_transaction_set_http_auth_scheme(transaction, auth_scheme);
                                                _set_authentication_info(transaction);
                                        }
-                                       transaction->completed_cb(transaction, transaction->completed_user_data);
+                                       if (transaction->completed_cb)
+                                               transaction->completed_cb(transaction, transaction->completed_user_data);
                                }
 
                                break;
@@ -119,6 +120,9 @@ gboolean timer_expired_callback(gpointer user_data)
 
        CURLMcode ret;
 
+       if (session == NULL || session->multi_handle == NULL)
+               return FALSE;
+
        ret = curl_multi_socket_action(session->multi_handle, CURL_SOCKET_TIMEOUT, 0, &(session->still_running));
        if (ret == CURLM_OK)
                DBG("CURLM_OK - Called curl_multi_socket_action()\n");
@@ -144,9 +148,9 @@ gboolean _handle_event(int fd, int action, gpointer user_data)
        else
                print_curl_multi_errorCode(ret);
 
-       _check_curl_multi_status(session);
 
        if (running_handles > 0) {
+               _check_curl_multi_status(session);
                return TRUE;
        } else {
                DBG("last transfer done, kill timeout\n");
@@ -154,6 +158,7 @@ gboolean _handle_event(int fd, int action, gpointer user_data)
                        g_source_remove(session->timer_event);
                        session->timer_event = 0;
                }
+               _check_curl_multi_status(session);
                return FALSE;
        }
 }
@@ -252,6 +257,11 @@ int __handle_timer_cb(CURLM *curl_multi, long timeout_ms, void *user_data)
 {
        __http_session_h* session = (__http_session_h *)user_data;
 
+       if (session->timer_event) {
+               g_source_remove(session->timer_event);
+               session->timer_event = 0;
+       }
+
        session->timer_event = g_timeout_add(timeout_ms , timer_expired_callback , session);
 
        return 0;
@@ -277,6 +287,7 @@ API int http_session_create(http_session_mode_e mode, http_session_h *http_sessi
        session->active_transaction_count = 0;
        session->session_mode = mode;
        session->auto_redirect = FALSE;
+       session->timer_event = 0;
 
        curl_multi_setopt(session->multi_handle, CURLMOPT_SOCKETFUNCTION, __handle_socket_cb);
        curl_multi_setopt(session->multi_handle, CURLMOPT_SOCKETDATA, session);
index 11967c9..8757690 100644 (file)
@@ -565,6 +565,18 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
                session->active_transaction_count--;
 
        if (transaction) {
+               if (transaction->thread_loop != NULL) {
+                       g_main_loop_quit((GMainLoop*)transaction->thread_loop);
+
+                       g_main_loop_unref(transaction->thread_loop);
+                       transaction->thread_loop = NULL;
+               }
+
+               if (transaction->thread != NULL) {
+                       g_thread_join(transaction->thread);
+                       transaction->thread = NULL;
+               }
+
                if (transaction->easy_handle != NULL) {
                        curl_easy_cleanup(transaction->easy_handle);
                        transaction->easy_handle = NULL;
@@ -682,18 +694,6 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
 
                _remove_transaction_from_list(transaction);
 
-               if (transaction->thread_loop != NULL) {
-                       g_main_loop_quit((GMainLoop*)transaction->thread_loop);
-
-                       g_main_loop_unref(transaction->thread_loop);
-                       transaction->thread_loop = NULL;
-               }
-
-               if (transaction->thread != NULL) {
-                       g_thread_join(transaction->thread);
-                       transaction->thread = NULL;
-               }
-
                free(transaction);
                transaction = NULL;
        }