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 <harshit.malpani@espressif.com>

Closes https://github.com/espressif/esp-idf/pull/13945
This commit is contained in:
fbp2m 2024-06-10 21:52:53 +02:00 committed by Harshit Malpani
parent f791c6e232
commit adb307da29
No known key found for this signature in database
GPG Key ID: 441A8ACC7853D493

View File

@ -662,9 +662,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;