Skip to content

Commit

Permalink
Merge branch 'bugfix/dpp_deinit_memleak_v52' into 'release/v5.2'
Browse files Browse the repository at this point in the history
Fix a memory leak in dpp deinit path(v5.2)

See merge request espressif/esp-idf!27680
  • Loading branch information
jack0c committed Dec 6, 2023
2 parents 56a6cad + 72176ee commit bdb0756
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 59 deletions.
6 changes: 6 additions & 0 deletions components/esp_common/src/esp_err_to_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ static const esp_err_msg_t esp_err_msg_table[] = {
# endif
# ifdef ESP_ERR_WIFI_DISCARD
ERR_TBL_IT(ESP_ERR_WIFI_DISCARD), /* 12315 0x301b Discard frame */
# endif
# ifdef ESP_ERR_WIFI_ROC_IN_PROGRESS
ERR_TBL_IT(ESP_ERR_WIFI_ROC_IN_PROGRESS), /* 12316 0x301c ROC op is in progress */
# endif
// components/wpa_supplicant/esp_supplicant/include/esp_wps.h
# ifdef ESP_ERR_WIFI_REGISTRAR
Expand Down Expand Up @@ -464,6 +467,9 @@ static const esp_err_msg_t esp_err_msg_table[] = {
# endif
# ifdef ESP_ERR_DPP_INVALID_ATTR
ERR_TBL_IT(ESP_ERR_DPP_INVALID_ATTR), /* 12441 0x3099 Encountered invalid DPP Attribute */
# endif
# ifdef ESP_ERR_DPP_AUTH_TIMEOUT
ERR_TBL_IT(ESP_ERR_DPP_AUTH_TIMEOUT), /* 12442 0x309a DPP Auth response was not recieved in time */
# endif
// components/esp_common/include/esp_err.h
# ifdef ESP_ERR_MESH_BASE
Expand Down
32 changes: 27 additions & 5 deletions components/esp_wifi/include/esp_wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ extern "C" {
#define ESP_ERR_WIFI_TWT_SETUP_TXFAIL (ESP_ERR_WIFI_BASE + 25) /*!< TWT setup frame tx failed */
#define ESP_ERR_WIFI_TWT_SETUP_REJECT (ESP_ERR_WIFI_BASE + 26) /*!< The twt setup request was rejected by the AP */
#define ESP_ERR_WIFI_DISCARD (ESP_ERR_WIFI_BASE + 27) /*!< Discard frame */
#define ESP_ERR_WIFI_ROC_IN_PROGRESS (ESP_ERR_WIFI_BASE + 28) /*!< ROC op is in progress */

/**
* @brief WiFi stack configuration parameters passed to esp_wifi_init call.
Expand Down Expand Up @@ -411,9 +412,9 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid);
/**
* @brief Scan all available APs.
*
* @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the
* will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause
* the memory to be freed once the scan is done
* @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory. And then
* can be freed in esp_wifi_scan_get_ap_records(), esp_wifi_scan_get_ap_record() or esp_wifi_clear_ap_list(),
* so call any one to free the memory once the scan is done.
* @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.
* Values above 1500ms may cause station to disconnect from AP and are not recommended.
*
Expand Down Expand Up @@ -460,7 +461,9 @@ esp_err_t esp_wifi_scan_stop(void);
esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);

/**
* @brief Get AP list found in last scan
* @brief Get AP list found in last scan.
*
* @attention This API will free all memory occupied by scanned AP list.
*
* @param[inout] number As input param, it stores max AP number ap_records can hold.
* As output param, it receives the actual AP number this API returns.
Expand All @@ -475,11 +478,30 @@ esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);
*/
esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records);

/**
* @brief Get one AP record from the scanned AP list.
*
* @attention Different from esp_wifi_scan_get_ap_records(), this API only gets one AP record
* from the scanned AP list each time. This API will free the memory of one AP record,
* if the user doesn't get all records in the scannned AP list, then needs to call esp_wifi_clear_ap_list()
* to free the remaining memory.
*
* @param[out] ap_record pointer to one AP record
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_FAIL: scan APs is NULL, means all AP records fetched or no AP found
*/
esp_err_t esp_wifi_scan_get_ap_record(wifi_ap_record_t *ap_record);

/**
* @brief Clear AP list found in last scan
*
* @attention When the obtained ap list fails,bss info must be cleared,otherwise it may cause memory leakage.
* @attention This API will free all memory occupied by scanned AP list.
* When the obtained AP list fails, AP records must be cleared,otherwise it may cause memory leakage.
*
* @return
* - ESP_OK: succeed
Expand Down
6 changes: 4 additions & 2 deletions components/wpa_supplicant/esp_supplicant/include/esp_dpp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -15,10 +15,12 @@
extern "C" {
#endif

#define ESP_DPP_AUTH_TIMEOUT_SECS 1

#define ESP_ERR_DPP_FAILURE (ESP_ERR_WIFI_BASE + 151) /*!< Generic failure during DPP Operation */
#define ESP_ERR_DPP_TX_FAILURE (ESP_ERR_WIFI_BASE + 152) /*!< DPP Frame Tx failed OR not Acked */
#define ESP_ERR_DPP_INVALID_ATTR (ESP_ERR_WIFI_BASE + 153) /*!< Encountered invalid DPP Attribute */

#define ESP_ERR_DPP_AUTH_TIMEOUT (ESP_ERR_WIFI_BASE + 154) /*!< DPP Auth response was not recieved in time */
/** @brief Types of Bootstrap Methods for DPP. */
typedef enum dpp_bootstrap_type {
DPP_BOOTSTRAP_QR_CODE, /**< QR Code Method */
Expand Down
Loading

0 comments on commit bdb0756

Please sign in to comment.