netutils/webclient: remove errout statement
This commit removes the 'errout' statement by changing the location of
the buffer allocation area.
@@ -1304,23 +1304,17 @@ int http_client_send_request(struct http_client_request_t *request,
return -1;
}
- request->buffer = (char *)malloc(request->buflen);
- if (request->buffer == NULL) {
- printf("Error: Fail to malloc buffer\n");
- return -1;
- }
-
request->callback = NULL;
request->tls = false;
request->response = response;
if (request->url == NULL) {
printf("Error: URL is NULL!!\n");
- goto errout;
+ return -1;
}
if (WEBCLIENT_CONF_MAX_ENTITY_SIZE < strlen(request->entity)) {
printf("Error: Too small buffer size\n");
- goto errout;
+ return -1;
}
#ifdef CONFIG_NET_SECURITY_TLS
if (ssl_conf) {
@@ -1330,17 +1324,20 @@ int http_client_send_request(struct http_client_request_t *request,
data = mallinfo();
if (data.fordblks < WEBCLIENT_CONF_MIN_TLS_MEMORY) {
printf("Error: Not enough memory!!\n");
- goto errout;
+ return -1;
}
}
#endif
- return client_send_request(request);
-errout:
- free(request->buffer);
+ request->buffer = (char *)malloc(request->buflen);
+ if (request->buffer == NULL) {
+ printf("Error: Fail to malloc buffer\n");
return -1;
}
+ return client_send_request(request);
+}
+
int http_client_send_request_async(struct http_client_request_t *request,
void *ssl_config,
wget_callback_t cb)
@@ -1359,23 +1356,17 @@ int http_client_send_request_async(struct http_client_request_t *request,
return -1;
}
- request->buffer = (char *)malloc(request->buflen);
- if (request->buffer == NULL) {
- printf("Error: Fail to malloc buffer\n");
- return -1;
- }
-
request->callback = cb;
request->tls = false;
request->response = NULL;
if (request->url == NULL) {
printf("Error: URL is NULL!!\n");
- goto errout;
+ return -1;
}
if (WEBCLIENT_CONF_MAX_ENTITY_SIZE < strlen(request->entity)) {
printf("Error: Too small buffer size\n");
- goto errout;
+ return -1;
}
#ifdef CONFIG_NET_SECURITY_TLS
if (ssl_conf) {
@@ -1385,17 +1376,20 @@ int http_client_send_request_async(struct http_client_request_t *request,
data = mallinfo();
if (data.fordblks < WEBCLIENT_CONF_MIN_TLS_MEMORY) {
printf("Error: Not enough memory!!\n");
- goto errout;
+ return -1;
}
}
#endif
- return client_send_request(request);
-errout:
- free(request->buffer);
+ request->buffer = (char *)malloc(request->buflen);
+ if (request->buffer == NULL) {
+ printf("Error: Fail to malloc buffer\n");
return -1;
}
+ return client_send_request(request);
+}
+
int http_client_response_init(struct http_client_response_t *response)
{
response->phrase = malloc(WEBCLIENT_CONF_MAX_PHRASE_SIZE);
