Fixed memory leak 24/113624/1 accepted/tizen/common/20170210.170545 accepted/tizen/mobile/20170214.010848 accepted/tizen/unified/20170309.031530 accepted/tizen/wearable/20170214.011015 submit/tizen/20170210.072732 submit/tizen/20170210.083740 submit/tizen_unified/20170308.100404
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 8 Feb 2017 07:58:07 +0000 (16:58 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 8 Feb 2017 07:58:49 +0000 (16:58 +0900)
WGID-146905, WGID-147913, WGID-148001
WGID-149782, WGID-169686, WGID-169772

Change-Id: I3006eb4c42be75736aae5fb4a2c82a5acf32eab6
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-http.spec
src/http_transaction.c
test/http_test.c

index 91f66e8..16071f6 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.19
+Version:       0.0.20
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index a1feb42..9f219e1 100644 (file)
@@ -491,6 +491,30 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
                return HTTP_ERROR_OUT_OF_MEMORY;
        }
 
+       transaction->request = (__http_request_h *)malloc(sizeof(__http_request_h));
+       if (transaction->request == NULL) {
+               ERR("Fail to allocate request memory!!");
+               free(transaction);
+               return HTTP_ERROR_OUT_OF_MEMORY;
+       }
+
+       transaction->response = (__http_response_h *)malloc(sizeof(__http_response_h));
+       if (transaction->response == NULL) {
+               ERR("Fail to allocate response memory!!");
+               free(transaction->request);
+               free(transaction);
+               return HTTP_ERROR_OUT_OF_MEMORY;
+       }
+
+       transaction->header = (__http_header_h *)malloc(sizeof(__http_header_h));
+       if (transaction->header == NULL) {
+               ERR("Fail to allocate header memory!!");
+               free(transaction->response);
+               free(transaction->request);
+               free(transaction);
+               return HTTP_ERROR_OUT_OF_MEMORY;
+       }
+
        transaction->easy_handle = NULL;
        transaction->timer_event = 0;
        transaction->interface_name = NULL;
@@ -517,29 +541,15 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
        transaction->session = http_session;
        transaction->session->active_transaction_count++;
 
-       transaction->request = (__http_request_h *)malloc(sizeof(__http_request_h));
-       if (transaction->request == NULL) {
-               ERR("Fail to allocate request memory!!");
-               return HTTP_ERROR_OUT_OF_MEMORY;
-       }
-
-       transaction->response = (__http_response_h *)malloc(sizeof(__http_response_h));
-       if (transaction->response == NULL) {
-               ERR("Fail to allocate response memory!!");
-               return HTTP_ERROR_OUT_OF_MEMORY;
-       }
-
-       transaction->header = (__http_header_h *)malloc(sizeof(__http_header_h));
-       if (transaction->header == NULL) {
-               ERR("Fail to allocate header memory!!");
-               return HTTP_ERROR_OUT_OF_MEMORY;
-       }
-
+       /* Header */
        transaction->header->rsp_header_len = 0;
        transaction->header->rsp_header = malloc(transaction->header->rsp_header_len + 1);
        transaction->header->rsp_header[0] = '\0';
+       transaction->header->header_list = NULL;
+       transaction->header->hash_table = NULL;
        transaction->header_event = FALSE;
 
+       /* Request */
        transaction->request->host_uri = NULL;
        transaction->request->method = _get_http_method(method);
        if (method == HTTP_METHOD_PUT)
@@ -558,11 +568,9 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
        transaction->request->formpost = NULL;
        transaction->request->lastptr = NULL;
 
+       /* Response */
        transaction->response->status_text = NULL;
 
-       transaction->header->header_list = NULL;
-       transaction->header->hash_table = NULL;
-
        *http_transaction = (http_transaction_h)transaction;
        _add_transaction_to_list(transaction);
 
@@ -1160,8 +1168,9 @@ API int http_transaction_open_authentication(http_transaction_h http_transaction
 
        auth_transaction->request = (__http_request_h *)malloc(sizeof(__http_request_h));
        if (auth_transaction->request == NULL) {
-               free(auth_transaction->interface_name);
-               free(auth_transaction->ca_path);
+               g_free(auth_transaction->interface_name);
+               g_free(auth_transaction->ca_path);
+               g_free(auth_transaction->realm);
                free(auth_transaction);
                ERR("Fail to allocate request memory!!");
                return HTTP_ERROR_OUT_OF_MEMORY;
@@ -1172,8 +1181,9 @@ API int http_transaction_open_authentication(http_transaction_h http_transaction
 
        auth_transaction->response = (__http_response_h *)malloc(sizeof(__http_response_h));
        if (auth_transaction->response == NULL) {
-               free(auth_transaction->interface_name);
-               free(auth_transaction->ca_path);
+               g_free(auth_transaction->interface_name);
+               g_free(auth_transaction->ca_path);
+               g_free(auth_transaction->realm);
                free(auth_transaction->request);
                free(auth_transaction);
                ERR("Fail to allocate response memory!!");
@@ -1182,8 +1192,9 @@ API int http_transaction_open_authentication(http_transaction_h http_transaction
 
        auth_transaction->header = (__http_header_h *)malloc(sizeof(__http_header_h));
        if (auth_transaction->header == NULL) {
-               free(auth_transaction->interface_name);
-               free(auth_transaction->ca_path);
+               g_free(auth_transaction->interface_name);
+               g_free(auth_transaction->ca_path);
+               g_free(auth_transaction->realm);
                free(auth_transaction->request);
                free(auth_transaction->response);
                free(auth_transaction);
index 84398db..e2a4f31 100644 (file)
@@ -95,6 +95,9 @@ void __transaction_completed_cb(http_transaction_h transaction, void *user_data)
                http_transaction_submit(http_auth_transaction);
        }
 
+       if (realm)
+               free(realm);
+
        if (uri)
                free(uri);
 }
@@ -264,6 +267,9 @@ int test_multiple_get(void)
        printf("Input count of transactions(1~10): ");
        ret = scanf("%d", &count);
 
+       if (count > 10)
+               count = 10;
+
        for (i = 0; i < count; i++) {
                char uri[1024];
                printf("Input uri for transaction[%d]: ", i + 1);