Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_esp_wifi_scan_start_memory_leakage_issue_v5.…
Browse files Browse the repository at this point in the history
…1' into 'release/v5.1'

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

See merge request espressif/esp-idf!29476
  • Loading branch information
jack0c committed Mar 11, 2024
2 parents e9fcccf + 3a2f9fe commit 4febc6e
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/wifi_provisioning/src/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,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) {
Expand Down
7 changes: 2 additions & 5 deletions components/wpa_supplicant/esp_supplicant/src/esp_scan.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/bluetooth/blufi/main/blufi_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions examples/wifi/ftm/main/ftm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions examples/wifi/iperf/main/cmd_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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;
}

Expand Down
4 changes: 1 addition & 3 deletions examples/wifi/roaming/main/roaming_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 4febc6e

Please sign in to comment.