netutils/webclient: duplicates memory allocation
authorJunyeon LEE <junyeon2.lee@samsung.com>
Tue, 23 May 2017 10:46:54 +0000 (19:46 +0900)
committerEunBong Song <eunb.song@samsung.com>
Tue, 11 Jul 2017 01:26:55 +0000 (10:26 +0900)
This commit fixes memory duplicated allocation problem in
webclient. If tls handshake retried, response buffer would be
able to be initialized double or triple times but release once.
Now that wget_base checkes buffer existance before allocating
a response buffer

Change-Id: I190827dd243df7d5be83170c904d23c40e036955
Signed-off-by: Junyeon LEE <junyeon2.lee@samsung.com>
apps/netutils/webclient/webclient.c

index d54bb59..aed5959 100644 (file)
@@ -990,14 +990,6 @@ retry:
                goto errout_before_tlsinit;
        }
 
-       if (param->callback) {
-               param->response = &response;
-               if (http_client_response_init(param->response) < 0) {
-                       ndbg("ERROR: response init failed: %d\n", ret);
-                       goto errout_before_tlsinit;
-               }
-       }
-
 #ifdef CONFIG_NET_SECURITY_TLS
        client_tls->client_fd = sockfd;
        if (param->tls && (ret = wget_tls_handshake(client_tls, ws.hostname))) {
@@ -1037,6 +1029,15 @@ retry:
                }
        }
 
+       if (param->callback && param->response == NULL) {
+               param->response = &response;
+               if (http_client_response_init(param->response) < 0) {
+                       ndbg("ERROR: response init failed: %d\n", ret);
+                       param->response = NULL;
+                       goto errout;
+               }
+       }
+
        buf_len = 0;
        while (!read_finish) {
                if (remain <= 0) {
@@ -1080,7 +1081,7 @@ retry:
                param->response->entity_len = strlen(param->response->entity);
        }
 
-       if (param->callback) {
+       if (param->callback && param->response) {
                param->callback(param->response);
                http_client_response_release(param->response);
        }
@@ -1099,7 +1100,7 @@ retry:
        return (pthread_addr_t)WGET_OK;
 
 errout:
-       if (param->callback) {
+       if (param->callback && param->response) {
                http_client_response_release(param->response);
        }
 #ifdef CONFIG_NET_SECURITY_TLS