From 8a8d01565e90632a4c96b8730ddb805c40e6ca8f Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Fri, 1 Aug 2025 11:44:06 +0800 Subject: [PATCH] fix(esp_http_client): fix possible double memory free --- components/esp_http_client/lib/http_utils.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/components/esp_http_client/lib/http_utils.c b/components/esp_http_client/lib/http_utils.c index 0b8f6d5924..e78f09edc3 100644 --- a/components/esp_http_client/lib/http_utils.c +++ b/components/esp_http_client/lib/http_utils.c @@ -68,15 +68,8 @@ char *http_utils_append_string(char **str, const char *new_str, int len) } if (old_str) { old_len = strlen(old_str); - // 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(old_str, NULL, TAG, "Memory exhausted"); - } - old_str = tmp; + old_str = realloc(old_str, old_len + l + 1); + mem_check(old_str); // Ensure the new string is null-terminated old_str[old_len + l] = 0; } else {