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
@@ -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
