http-client: fix memory allocation issues found by static analyser
@@ -621,14 +621,22 @@ esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client)
}
esp_http_client_close(client);
esp_transport_list_destroy(client->transport_list);
+ if (client->request) {
http_header_destroy(client->request->headers);
+ if (client->request->buffer) {
free(client->request->buffer->data);
+ }
free(client->request->buffer);
free(client->request);
+ }
+ if (client->response) {
http_header_destroy(client->response->headers);
+ if (client->response->buffer) {
free(client->response->buffer->data);
+ }
free(client->response->buffer);
free(client->response);
+ }
free(client->parser);
free(client->parser_settings);
@@ -700,7 +708,10 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
if (purl.field_data[UF_HOST].len) {
http_utils_assign_string(&client->connection_info.host, url + purl.field_data[UF_HOST].off, purl.field_data[UF_HOST].len);
- HTTP_MEM_CHECK(TAG, client->connection_info.host, return ESP_ERR_NO_MEM);
+ HTTP_MEM_CHECK(TAG, client->connection_info.host, {
+ free(old_host);
+ return ESP_ERR_NO_MEM;
+ });
}
// Close the connection if host was changed
if (old_host && client->connection_info.host
