mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 03:34:32 +02:00
Merge branch 'bugfix/fix_memory_leak_on_http_header_fetch_failure_v5.2' into 'release/v5.2'
fix(esp_http_client): free header in case of ESP_ERR_HTTP_FETCH_HEADER (v5.2) See merge request espressif/esp-idf!40666
This commit is contained in:
@@ -928,6 +928,7 @@ esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client)
|
||||
_clear_auth_data(client);
|
||||
free(client->auth_data);
|
||||
free(client->current_header_key);
|
||||
free(client->current_header_value);
|
||||
free(client->location);
|
||||
free(client->auth_header);
|
||||
free(client);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "http_utils.h"
|
||||
#include "esp_check.h"
|
||||
|
||||
#ifndef mem_check
|
||||
#define mem_check(x) assert(x)
|
||||
@@ -64,8 +65,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);
|
||||
mem_check(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, "http_utils", "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