Skip to content

Commit

Permalink
Do not allocate client->if_name twice in esp_http_client_init.
Browse files Browse the repository at this point in the history
When if_name is specified in config and CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS is set, client->if_name is allocated twice, and first one is never free.
  • Loading branch information
fbp2m committed Jun 10, 2024
1 parent 8760e6d commit f80749b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions components/esp_http_client/esp_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f80749b

Please sign in to comment.