Merge branch 'bugfix/fix_esp_wifi_scan_start_memory_leakage_issue_v5.0' into 'release/v5.0'

fix(wifi): fix esp_wifi_scan_start memory leakage issue(Backport v5.0)

See merge request espressif/esp-idf!29477
This commit is contained in:
Jiang Jiang Jian 2024-03-11 11:19:31 +08:00
commit c286a416ba
7 changed files with 8 additions and 8 deletions

View File

@ -770,6 +770,7 @@ static esp_err_t update_wifi_scan_results(void)
prov_ctx->ap_list[curr_channel] = (wifi_ap_record_t *) calloc(get_count, sizeof(wifi_ap_record_t));
if (!prov_ctx->ap_list[curr_channel]) {
ESP_LOGE(TAG, "Failed to allocate memory for AP list");
esp_wifi_clear_ap_list();
goto exit;
}
if (esp_wifi_scan_get_ap_records(&get_count, prov_ctx->ap_list[curr_channel]) != ESP_OK) {

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -66,13 +66,10 @@ static void handle_wnm_scan_done(struct wpa_supplicant *wpa_s)
static void scan_done_cleanup(struct wpa_supplicant *wpa_s)
{
uint16_t number = 1;
wifi_ap_record_t ap_records;
wpa_s->scanning = 0;
wpa_s->scan_reason = 0;
/* clean scan list from net80211 */
esp_wifi_scan_get_ap_records(&number, &ap_records);
esp_wifi_clear_ap_list();
}
void esp_supplicant_handle_scan_done_evt(void)

View File

@ -208,6 +208,7 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
wifi_ap_record_t *ap_list = (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * apCount);
if (!ap_list) {
BLUFI_ERROR("malloc error, ap_list is NULL");
esp_wifi_clear_ap_list();
break;
}
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&apCount, ap_list));

View File

@ -67,6 +67,7 @@ static void scan_done_handler(void)
ap_list_buffer = malloc(sta_number * sizeof(wifi_ap_record_t));
if (ap_list_buffer == NULL) {
ESP_LOGE(TAG, "Failed to malloc buffer to print scan results");
esp_wifi_clear_ap_list();
return;
}

View File

@ -304,6 +304,7 @@ static bool wifi_perform_scan(const char *ssid, bool internal)
g_ap_list_buffer = malloc(g_scan_ap_num * sizeof(wifi_ap_record_t));
if (g_ap_list_buffer == NULL) {
ESP_LOGE(TAG_STA, "Failed to malloc buffer to print scan results");
esp_wifi_clear_ap_list();
return false;
}

View File

@ -76,6 +76,7 @@ static void scan_done_handler(void *arg, esp_event_base_t event_base,
ap_list_buffer = malloc(sta_number * sizeof(wifi_ap_record_t));
if (ap_list_buffer == NULL) {
ESP_LOGE(TAG, "Failed to malloc buffer to print scan results");
esp_wifi_clear_ap_list();
return;
}

View File

@ -305,9 +305,7 @@ void neighbor_report_recv_cb(void *ctx, const uint8_t *report, size_t report_len
goto cleanup;
}
/* cleanup from net802.11 */
uint16_t number = 1;
wifi_ap_record_t ap_records;
esp_wifi_scan_get_ap_records(&number, &ap_records);
esp_wifi_clear_ap_list();
cand_list = 1;
}
/* send AP btm query, this will cause STA to roam as well */