mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-25 17:58:46 +00:00
fix(esp_http_client): fix memory leak in current_header_value buffer
Fixed memory leak in esp_http_client_cleanup() where current_header_value buffer was not being freed when ESP_ERR_HTTP_FETCH_HEADER is returned during header parsing failures.
This commit is contained in:
@@ -68,8 +68,16 @@ char *http_utils_append_string(char **str, const char *new_str, int len)
|
||||
}
|
||||
if (old_str) {
|
||||
old_len = strlen(old_str);
|
||||
old_str = realloc(old_str, old_len + l + 1);
|
||||
ESP_RETURN_ON_FALSE(old_str, NULL, TAG, "Memory exhausted");
|
||||
// old_str should not be reallocated directly, as in case of memory exhaustion,
|
||||
// it will be lost and we will not be able to free it.
|
||||
char *tmp = realloc(old_str, old_len + l + 1);
|
||||
if (tmp == NULL) {
|
||||
free(old_str);
|
||||
old_str = NULL;
|
||||
ESP_RETURN_ON_FALSE(tmp, NULL, TAG, "Memory exhausted");
|
||||
}
|
||||
old_str = tmp;
|
||||
// Ensure the new string is null-terminated
|
||||
old_str[old_len + l] = 0;
|
||||
} else {
|
||||
old_str = calloc(1, l + 1);
|
||||
|
Reference in New Issue
Block a user