Fix memory leak 14/140514/1 accepted/tizen/4.0/unified/20170816.012347 accepted/tizen/4.0/unified/20170828.223820 accepted/tizen/unified/20170803.075453 submit/tizen/20170731.020626 submit/tizen/20170801.224410 submit/tizen/20170802.055623 submit/tizen/20170802.230359 submit/tizen/20170803.010203 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170828.100002
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 25 Jul 2017 08:06:00 +0000 (17:06 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 25 Jul 2017 08:06:10 +0000 (17:06 +0900)
Change-Id: Ic25450ef9e8e6dc4e383039cd87df732485ffeb8
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-http.spec
src/http_request.c
src/http_transaction.c

index 37ae2ef..7d8e0a1 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.26
+Version:       0.0.27
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index a3c8c8b..9f1fac7 100644 (file)
@@ -334,7 +334,8 @@ int _read_request_body(http_transaction_h http_transaction, char **body)
        int body_size = 0;
        int curr_len = 0;
        size_t new_len = 0;
-       gchar* ptr = NULL;
+       gchar *ptr = NULL;
+       char *tmp = NULL;
 
        len = g_queue_get_length(request->body_queue);
        if (len == 0) {
@@ -349,20 +350,21 @@ int _read_request_body(http_transaction_h http_transaction, char **body)
        }
 
        for (index = 0; index < len; index++) {
-
-               ptr = (gchar*)g_queue_pop_head(request->body_queue);
+               ptr = (gchar *)g_queue_pop_head(request->body_queue);
                if (!ptr) {
                        DBG("body_queue is empty\n");
                        break;
                }
 
                body_size = strlen(ptr);
-
                new_len = curr_len + body_size;
-               *body = realloc(*body, new_len + 1);
-               if (*body == NULL) {
+
+               tmp = (char *)realloc(*body, new_len + 1);
+               if (tmp == NULL) {
                        DBG("realloc() failed\n");
                        return HTTP_ERROR_OUT_OF_MEMORY;
+               } else {
+                       *body = tmp;
                }
 
                memcpy(*body + curr_len, ptr, body_size);
index 8f65c8b..a9ea3ec 100644 (file)
@@ -74,16 +74,16 @@ size_t __handle_header_cb(gchar *buffer, size_t size, size_t nmemb, gpointer use
        __http_transaction_h *transaction = (__http_transaction_h *)user_data;
        __http_header_h *header = transaction->header;
 
-       gchar *temp_header = NULL;
+       gchar *tmp = NULL;
        size_t written = size * nmemb;
        size_t new_len = header->rsp_header_len + written;
 
-       temp_header = header->rsp_header;
-       header->rsp_header = realloc(header->rsp_header, new_len + 1);
-       if (header->rsp_header == NULL) {
-               free(temp_header);
+       tmp = (gchar *)realloc(header->rsp_header, new_len + 1);
+       if (tmp == NULL) {
                ERR("realloc() failed\n");
                return -1;
+       } else {
+               header->rsp_header = tmp;
        }
 
        memcpy(header->rsp_header + header->rsp_header_len, buffer, written);
@@ -424,8 +424,10 @@ int _transaction_submit(gpointer user_data)
                gchar *body = NULL;
 
                ret = _read_request_body(transaction, &body);
-               if (ret != HTTP_ERROR_NONE)
+               if (ret != HTTP_ERROR_NONE) {
+                       g_free(body);
                        return ret;
+               }
 
                if (body) {
                        curl_easy_setopt(transaction->easy_handle, CURLOPT_COPYPOSTFIELDS, body);