Merge branch 'fix(esp_http_client)/fix_potential_double_free_v5.2' into 'release/v5.2'

fix(esp_http_client): fix possible double memory free (v5.2)

See merge request espressif/esp-idf!40980
This commit is contained in:
Mahavir Jain
2025-08-05 09:50:03 +05:30

View File

@@ -65,15 +65,8 @@ char *http_utils_append_string(char **str, const char *new_str, int len)
} }
if (old_str) { if (old_str) {
old_len = strlen(old_str); old_len = strlen(old_str);
// old_str should not be reallocated directly, as in case of memory exhaustion, old_str = realloc(old_str, old_len + l + 1);
// it will be lost and we will not be able to free it. mem_check(old_str);
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, "http_utils", "Memory exhausted");
}
old_str = tmp;
// Ensure the new string is null-terminated // Ensure the new string is null-terminated
old_str[old_len + l] = 0; old_str[old_len + l] = 0;
} else { } else {