From 975e77ed7d8048ad30335c66477a7177a1649074 Mon Sep 17 00:00:00 2001 From: fbp2m Date: Mon, 10 Jun 2024 21:52:53 +0200 Subject: [PATCH] fix: fixed allocating if_name in client context multiple times Do not allocate client->if_name twice in esp_http_client_init(). Signed-off-by: Harshit Malpani Closes https://github.com/espressif/esp-idf/pull/13945 --- components/esp_http_client/esp_http_client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 0a9534f20d..71a4940c83 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -641,9 +641,11 @@ static bool init_common_tcp_transport(esp_http_client_handle_t client, const esp } if (config->if_name) { - client->if_name = calloc(1, sizeof(struct ifreq)); - ESP_RETURN_ON_FALSE(client->if_name, false, TAG, "Memory exhausted"); - memcpy(client->if_name, config->if_name, sizeof(struct ifreq)); + if (client->if_name == NULL) { + client->if_name = calloc(1, sizeof(struct ifreq)); + ESP_RETURN_ON_FALSE(client->if_name, false, TAG, "Memory exhausted"); + memcpy(client->if_name, config->if_name, sizeof(struct ifreq)); + } esp_transport_tcp_set_interface_name(transport, client->if_name); } return true;