From 8a1da21b1a128f995fc6d8370e88a19f6ab418d4 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 13 Jan 2019 17:14:20 +0100 Subject: [PATCH] cpu/esp32: fixes serious memory leak in esp_wifi The buffer given by the WiFi driver as parameter eb has to be freed explicitly. Otherwise the esp_wifi_netdev stops working after some seconds. --- cpu/esp32/esp-wifi/esp_wifi_netdev.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cpu/esp32/esp-wifi/esp_wifi_netdev.c b/cpu/esp32/esp-wifi/esp_wifi_netdev.c index c3b8dc3d0e..fcd80cb1f0 100644 --- a/cpu/esp32/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp32/esp-wifi/esp_wifi_netdev.c @@ -74,12 +74,22 @@ esp_err_t _esp_wifi_rx_cb(void *buffer, uint16_t len, void *eb) { DEBUG("%s: buf=%p len=%d eb=%p\n", __func__, buffer, len, eb); - CHECK_PARAM_RET (buffer != NULL, -EINVAL); - CHECK_PARAM_RET (len <= ETHERNET_DATA_LEN, -EINVAL); + if ((buffer == NULL) || (len >= ETHERNET_DATA_LEN)) { + if (eb != NULL) { + esp_wifi_internal_free_rx_buffer(eb); + } + return ESP_ERR_INVALID_ARG; + } mutex_lock(&_esp_wifi_dev.dev_lock); + /* copy the buffer and free WiFi driver buffer */ memcpy(_esp_wifi_dev.rx_buf, buffer, len); + if (eb) { + esp_wifi_internal_free_rx_buffer(eb); + } + + /* trigger netdev event to read the data */ _esp_wifi_dev.rx_len = len; _esp_wifi_dev.event = SYSTEM_EVENT_WIFI_RX_DONE; _esp_wifi_dev.netdev.event_callback(&_esp_wifi_dev.netdev, NETDEV_EVENT_ISR);