refactoring download-provider alloc/free accepted/tizen/unified/20170411.035337 submit/tizen/20170411.023557
authormin7.choi <min7.choi@samsung.com>
Mon, 10 Apr 2017 17:39:45 +0000 (02:39 +0900)
committerjaekuk, lee <juku1999@samsung.com>
Tue, 11 Apr 2017 02:35:36 +0000 (11:35 +0900)
Change-Id: I413491d1f50ef28e4790d2123d3079b232aab469
Signed-off-by: min7.choi <min7.choi@samsung.com>
agent/download-agent-dl-info.c
agent/download-agent-http-msg-handler.c
agent/include/download-agent-type.h
packaging/download-provider.spec

index 123cf7d..2925f78 100644 (file)
@@ -313,38 +313,37 @@ static void __destroy_http_msg_response(http_msg_response_t *msg)
 static void __destroy_req_info(req_info_t *req_info)
 {
        if (req_info) {
-               free(req_info->url);
+               NULL_CHECK_AND_FREE(req_info->url);
                if (req_info->req_header && req_info->req_header_count > 0) {
                        int i = 0;
                        int count = req_info->req_header_count;
                        for (i = 0; i < count; i++)     {
-                               free(req_info->req_header[i]);
+                               NULL_CHECK_AND_FREE(req_info->req_header[i]);
                                req_info->req_header[i] = DA_NULL;
                        }
-                       free(req_info->req_header);
+                       NULL_CHECK_AND_FREE(req_info->req_header);
                        req_info->req_header = DA_NULL;
                        req_info->req_header_count = 0;
                }
-               free(req_info->install_path);
-               free(req_info->file_name);
-               free(req_info->etag);
-               free(req_info->temp_file_path);
-               free(req_info->pkg_name);
+               NULL_CHECK_AND_FREE(req_info->install_path);
+               NULL_CHECK_AND_FREE(req_info->file_name);
+               NULL_CHECK_AND_FREE(req_info->etag);
+               NULL_CHECK_AND_FREE(req_info->temp_file_path);
+               NULL_CHECK_AND_FREE(req_info->pkg_name);
                req_info->user_req_data = DA_NULL;
                req_info->user_client_data = DA_NULL;
-               free(req_info);
+               NULL_CHECK_AND_FREE(req_info);
        }
 }
 
 void destroy_http_info(http_info_t *http_info)
 {
        if (http_info) {
-               DA_LOGI("[TEST] location_url[%p]",http_info->location_url);
-               free(http_info->location_url);
-               free(http_info->proxy_addr);
-               free(http_info->content_type_from_header);
-               free(http_info->etag_from_header);
-               free(http_info->file_name_from_header);
+               NULL_CHECK_AND_FREE(http_info->location_url);
+               NULL_CHECK_AND_FREE(http_info->proxy_addr);
+               NULL_CHECK_AND_FREE(http_info->content_type_from_header);
+               NULL_CHECK_AND_FREE(http_info->etag_from_header);
+               NULL_CHECK_AND_FREE(http_info->file_name_from_header);
                if (http_info->http_msg_request) {
                        __destroy_http_msg_request(http_info->http_msg_request);
                        http_info->http_msg_request = DA_NULL;
@@ -365,7 +364,7 @@ void destroy_http_info(http_info_t *http_info)
                http_info->content_len_from_header = 0;
                http_info->total_size = 0;
                http_info->error_code = 0;
-               free(http_info);
+               NULL_CHECK_AND_FREE(http_info);
        }
 }
 
@@ -373,11 +372,11 @@ void destroy_file_info(file_info_t *file_info)
 {
        if (file_info) {
                file_info->file_handle = DA_NULL;
-               free(file_info->pure_file_name);
-               free(file_info->extension);
-               free(file_info->file_path);
-               free(file_info->mime_type);
-               free(file_info->buffer);
+               NULL_CHECK_AND_FREE(file_info->pure_file_name);
+               NULL_CHECK_AND_FREE(file_info->extension);
+               NULL_CHECK_AND_FREE(file_info->file_path);
+               NULL_CHECK_AND_FREE(file_info->mime_type);
+               NULL_CHECK_AND_FREE(file_info->buffer);
                file_info->buffer_len = 0;
                file_info->file_size = 0;
 #ifdef _RAF_SUPPORT
@@ -385,7 +384,7 @@ void destroy_file_info(file_info_t *file_info)
 #endif
                file_info->bytes_written_to_file = 0;
                file_info->is_updated = DA_FALSE;
-               free(file_info);
+               NULL_CHECK_AND_FREE(file_info);
        }
 }
 
@@ -394,11 +393,11 @@ void reset_http_info_for_resume(http_info_t *http_info)
 {
        if (http_info) {
                DA_LOGI("[TEST] location_url[%p]",http_info->location_url);
-               free(http_info->location_url);
+               NULL_CHECK_AND_FREE(http_info->location_url);
                http_info->location_url = DA_NULL;
-               free(http_info->proxy_addr);
+               NULL_CHECK_AND_FREE(http_info->proxy_addr);
                http_info->proxy_addr = DA_NULL;
-               free(http_info->content_type_from_header);
+               NULL_CHECK_AND_FREE(http_info->content_type_from_header);
                http_info->content_type_from_header = DA_NULL;
                if (http_info->http_msg_response) {
                        __destroy_http_msg_response(http_info->http_msg_response);
index fe507d6..cc21267 100755 (executable)
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
+#include <curl/curl.h>
 
 #include "download-agent-http-msg-handler.h"
 #include "download-agent-debug.h"
@@ -810,26 +811,35 @@ da_bool_t http_msg_response_get_content_disposition(
                                DA_LOGV("It's NOT base64 encoded-word string");
                        }
 
-                       if(http_msg->curl)
+                       if(http_msg->curl){
                                decoded_str = curl_easy_unescape(http_msg->curl, wanted_str, wanted_str_len, NULL);
+                       }
+                       else{
+                               CURL* handle = curl_easy_init();
+                               decoded_str = curl_easy_unescape(handle, wanted_str, wanted_str_len, NULL);
+                               curl_easy_cleanup(handle);
+                       }
 
                        /* If it is url encoded string */
                        if (decoded_str) {
+                               char* file_name;
                                DA_SECURE_LOGD("Url decoded str = [%s]", decoded_str);
-                               free(wanted_str);
-                               wanted_str = decoded_str;
+                               file_name = (char*)calloc(1, strlen(decoded_str) + 1);
+                               strncpy(file_name, decoded_str, strlen(decoded_str));
+
+                               NULL_CHECK_AND_FREE(wanted_str);
+                               curl_free(decoded_str);
                                decoded_str = NULL;
+
+                               *out_file_name = file_name;
+                               return DA_TRUE;
                        }
                        else{
                                DA_LOGE("Fail to url decode.");
-                               free(wanted_str);
-                               wanted_str = NULL;
+                               NULL_CHECK_AND_FREE(wanted_str);
+                               *out_file_name = NULL;
                                return DA_FALSE;
                        }
-                       *out_file_name = wanted_str;
-
-                       DA_SECURE_LOGI("out_file_name = [%s]", *out_file_name);
-                       return DA_TRUE;
                } else {
                        DA_LOGE("Not matched \" !");
                        return DA_FALSE;
index 02d4674..2e2d525 100755 (executable)
@@ -72,5 +72,11 @@ typedef unsigned long long da_size_t;
        }\
 }
 
+#define NULL_CHECK_AND_FREE(DATA) {\
+       if(DATA) {\
+               free(DATA);\
+               DATA=DA_NULL;\
+       }\
+}
 #endif
 
index 5af1f3a..5c0a45e 100755 (executable)
@@ -1,7 +1,7 @@
 %define _ux_define tizen2.3
 Name:       download-provider
 Summary:    Download the contents in background
-Version:    2.1.74
+Version:    2.1.75
 Release:    0
 Group:      Development/Libraries
 License:    Apache-2.0