wifi: esp32: fix memory leak

In case where the system is overloaded, net stack buffer
could fail to allocate next packet. That scenario requires
wifi internal Wi-Fi driver to free current rx buffer. This is
currently not being called. This fixes it by making sure
esp_wifi_internal_free_rx_buffer() is called in all scenarios.

Fixes #63043

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
This commit is contained in:
Sylvio Alves 2024-07-04 18:06:51 -03:00 committed by Anas Nashif
parent 1c19d43564
commit 6ade0cf715

View File

@ -117,18 +117,20 @@ static esp_err_t eth_esp32_rx(void *buffer, uint16_t len, void *eb)
struct net_pkt *pkt;
if (esp32_wifi_iface == NULL) {
esp_wifi_internal_free_rx_buffer(eb);
LOG_ERR("network interface unavailable");
return -EIO;
}
pkt = net_pkt_rx_alloc_with_buffer(esp32_wifi_iface, len, AF_UNSPEC, 0, K_MSEC(100));
if (!pkt) {
LOG_ERR("Failed to get net buffer");
LOG_ERR("Failed to allocate net buffer");
esp_wifi_internal_free_rx_buffer(eb);
return -EIO;
}
if (net_pkt_write(pkt, buffer, len) < 0) {
LOG_ERR("Failed to write pkt");
LOG_ERR("Failed to write to net buffer");
goto pkt_unref;
}
@ -146,6 +148,7 @@ static esp_err_t eth_esp32_rx(void *buffer, uint16_t len, void *eb)
return 0;
pkt_unref:
esp_wifi_internal_free_rx_buffer(eb);
net_pkt_unref(pkt);
#if defined(CONFIG_NET_STATISTICS_WIFI)