From: Seonah Moon Date: Wed, 8 Feb 2017 07:58:07 +0000 (+0900) Subject: Fixed memory leak X-Git-Tag: submit/tizen/20170210.072732^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a1e8a9b75814fba074d33d0a5719aa2f3cb9c57;p=platform%2Fcore%2Fapi%2Fhttp.git Fixed memory leak WGID-146905, WGID-147913, WGID-148001 WGID-149782, WGID-169686, WGID-169772 Change-Id: I3006eb4c42be75736aae5fb4a2c82a5acf32eab6 Signed-off-by: Seonah Moon --- diff --git a/packaging/capi-network-http.spec b/packaging/capi-network-http.spec index 91f66e8..16071f6 100644 --- a/packaging/capi-network-http.spec +++ b/packaging/capi-network-http.spec @@ -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 diff --git a/src/http_transaction.c b/src/http_transaction.c index a1feb42..9f219e1 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -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); diff --git a/test/http_test.c b/test/http_test.c index 84398db..e2a4f31 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -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);