[capi-http] Fixed crashes in http_transaction_destroy & http_session_destroy 15/69215/3
authorpradeep kumar B <b.pradeep@samsung.com>
Thu, 12 May 2016 07:33:56 +0000 (13:03 +0530)
committerpradeep kumar B <b.pradeep@samsung.com>
Thu, 12 May 2016 09:47:32 +0000 (15:17 +0530)
Change-Id: I5f20026a296cee68f2051f58f401ba5609d344c9
Signed-off-by: pradeep kumar B <b.pradeep@samsung.com>
include/http.h
packaging/capi-network-http.spec
src/http_session.c
src/http_transaction.c
test/http_test.c

index 45632f0..a4a4318 100644 (file)
@@ -298,6 +298,7 @@ int http_session_create(http_session_mode_e mode, http_session_h *http_session);
 /**
  * @brief Destroys the Http session handle.
  * @since_tizen 3.0
+ * @remarks http_session should be set to NULL after using it
  * @param[in]  http_session  The http session handle
  * @return 0 on success, otherwise negative error value
  * @retval  #HTTP_ERROR_NONE  Successful
@@ -381,6 +382,7 @@ int http_session_get_max_transaction_count(http_session_h http_session, int *tra
 /*
  * @brief Destroys all transaction.
  * @since_tizen 3.0
+ * @remarks All http_transactions should be set to NULL after using it
  * @param[in]  http_session  The http session handle
  * @return 0 on success, otherwise negative error value
  * @retval  #HTTP_ERROR_NONE  Successful
@@ -418,7 +420,7 @@ int http_transaction_submit(http_transaction_h http_transaction);
  * @brief Closes the http transaction handle.
  * @since_tizen 3.0
  * @remarks  The @a transaction is released by http_transaction_destroy().
- *                      It should be used after finishing http trasaction.
+ *                      http_transaction should be set to NULL after using it.
  * @param[in]  http_transaction  The http transaction handle
  * @return 0 on success, otherwise negative error value
  * @retval  #HTTP_ERROR_NONE  Successful
index 7e348f0..e586ffd 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.4
+Version:       0.0.5
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index 1431543..6b0e2b3 100644 (file)
@@ -64,7 +64,9 @@ void _check_curl_multi_status(gpointer user_data)
                                break;
                        }
 
-                       curl_multi_remove_handle(session->multi_handle, curl_easy);
+                       if (session->multi_handle != NULL && curl_easy != NULL) {
+                               curl_multi_remove_handle(session->multi_handle, curl_easy);
+                       }
                }
                message = curl_multi_info_read(session->multi_handle, &count);
        }
@@ -264,16 +266,24 @@ API int http_session_destroy(http_session_h http_session)
 
        __http_session_h *session = (__http_session_h *)http_session;
 
-       if (session->multi_handle) {
-               curl_multi_cleanup(session->multi_handle);
-               session->multi_handle = NULL;
-       }
+       if (session) {
+               if (session->multi_handle) {
+                       curl_multi_cleanup(session->multi_handle);
+                       session->multi_handle = NULL;
+               }
 
-       session->active_transaction_count = 0;
-       session->still_running = 0;
-       session->auto_redirect = FALSE;
+               session->active_transaction_count = 0;
+               session->still_running = 0;
+               session->auto_redirect = FALSE;
 
-       free(session);
+               if (session->timer_event) {
+                       g_source_remove(session->timer_event);
+                       session->timer_event = 0;
+               }
+
+               free(session);
+               session = NULL;
+       }
 
        return HTTP_ERROR_NONE;
 }
index a07f5af..2639459 100644 (file)
@@ -337,10 +337,13 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
        transaction->request->body_queue = g_queue_new();
        transaction->request->tot_size = 0;
 
+       transaction->response->status_text = NULL;
+
        transaction->header->header_list = NULL;
        transaction->header->hash_table = NULL;
 
        transaction->thread = NULL;
+       transaction->thread_loop = NULL;
 
        *http_transaction = (http_transaction_h)transaction;
        _add_transaction_to_list(transaction);
@@ -439,7 +442,17 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
 
                        free(request);
                }
-               free(response);
+
+               if (response) {
+
+                       if (response->status_text != NULL) {
+                               free(response->status_text);
+                               response->status_text = NULL;
+                       }
+
+                       free(response);
+
+               }
 
                if (header) {
                        if (header->header_list != NULL) {
@@ -457,13 +470,17 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
 
                _remove_transaction_from_list(transaction);
 
-               g_main_loop_quit((GMainLoop*)transaction->thread_loop);
+               if (transaction->thread_loop != NULL) {
+                       g_main_loop_quit((GMainLoop*)transaction->thread_loop);
 
-               g_main_loop_unref(transaction->thread_loop);
-               transaction->thread_loop = NULL;
+                       g_main_loop_unref(transaction->thread_loop);
+                       transaction->thread_loop = NULL;
+               }
 
-               g_thread_join(transaction->thread);
-               transaction->thread = NULL;
+               if (transaction->thread != NULL) {
+                       g_thread_join(transaction->thread);
+                       transaction->thread = NULL;
+               }
 
                free(transaction);
                transaction = NULL;
index 8c370c7..9ce9c61 100644 (file)
@@ -66,6 +66,8 @@ void __transaction_completed_cb(http_transaction_h transaction, void *user_data)
        ret = http_transaction_destroy(transaction);
        if (ret == HTTP_ERROR_NONE) DBG("Success to close transaction\n");
        else DBG("Fail to close transaction\n");
+
+       transaction = NULL;
 }
 
 void __transaction_aborted_cb(http_transaction_h transaction, int reason, void *user_data)
@@ -123,6 +125,8 @@ int test_http_session_destroy(void)
                return 0;
        }
 
+       session = NULL;
+
        return 1;
 }