Przeglądaj źródła

esp_wifi: fix WiFi deinit memory leak

liu zhifu 6 lat temu
rodzic
commit
19e355e080

+ 17 - 0
components/esp_wifi/include/esp_private/wifi.h

@@ -102,6 +102,23 @@ typedef enum {
  */
 esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config);
 
+/**
+ * @brief Deinitialize Wi-Fi Driver
+ *     Free resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
+ *     WiFi NVS structure among others.
+ *
+ * For the most part, you need not call this function directly. It gets called
+ * from esp_wifi_deinit().
+ *
+ * This function may be called, if you call esp_wifi_init_internal to initialize
+ * WiFi driver.
+ *
+ * @return
+ *    - ESP_OK: succeed
+ *    - others: refer to error code esp_err.h
+ */
+esp_err_t esp_wifi_deinit_internal(void);
+
 /**
   * @brief  get whether the wifi driver is allowed to transmit data or not
   *

+ 1 - 1
components/esp_wifi/lib_esp32

@@ -1 +1 @@
-Subproject commit e0e387d9118a5e7c939b8025e8db680c5620a6a2
+Subproject commit e386debd1f288c59c4d07f41f4f3cac395388d51

+ 15 - 0
components/esp_wifi/src/wifi_init.c

@@ -96,6 +96,21 @@ static void esp_wifi_set_debug_log()
 
 }
 
+esp_err_t esp_wifi_deinit(void)
+{
+    esp_err_t err = ESP_OK;
+
+    esp_supplicant_deinit();
+    err = esp_wifi_deinit_internal();
+    if (err != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to deinit Wi-Fi driver (0x%x)", err);
+    }
+
+    tcpip_adapter_clear_default_wifi_handlers();
+
+    return err;
+}
+
 esp_err_t esp_wifi_init(const wifi_init_config_t *config)
 {
 #ifdef CONFIG_PM_ENABLE

+ 10 - 0
components/wpa_supplicant/include/esp_supplicant/esp_wpa.h

@@ -54,6 +54,16 @@ const mesh_crypto_funcs_t g_wifi_default_mesh_crypto_funcs;
   */
 esp_err_t esp_supplicant_init(void);
 
+/**
+  * @brief     Supplicant deinitialization
+  *
+  * @return    
+  *          - ESP_OK : succeed
+  *          - others: failed
+  */
+esp_err_t esp_supplicant_deinit(void);
+
+
 /**
   * @}
   */

+ 1 - 1
components/wpa_supplicant/src/esp_supplicant/esp_wpa_main.c

@@ -232,7 +232,7 @@ int esp_supplicant_init(void)
     return ESP_OK;
 }
 
-bool  wpa_hook_deinit(void)
+int esp_supplicant_deinit(void)
 {
     return esp_wifi_unregister_wpa_cb_internal();
 }