From 35958ea2c6fb5760ddf5a3d03d3a98b9d188b5f6 Mon Sep 17 00:00:00 2001 From: Junyeon LEE Date: Tue, 23 May 2017 19:46:54 +0900 Subject: [PATCH] netutils/webclient: duplicates memory allocation 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 --- apps/netutils/webclient/webclient.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/netutils/webclient/webclient.c b/apps/netutils/webclient/webclient.c index d54bb59..aed5959 100644 --- a/apps/netutils/webclient/webclient.c +++ b/apps/netutils/webclient/webclient.c @@ -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 -- 2.7.4