-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please explain esp_wifi_clear_ap_list() (IDFGH-9313) #10693
Comments
You can try searching this function on github. |
Above code you mentioned just calls esp_wifi_scan_get_ap_records() for each esp_wifi_scan_get_ap_records(), no matter it's success or fail. Are you sure this is correct? If so, then there must be a memory leak in older esp-idf versions. From the wording of the comment: @brief Clear AP list found in last scan |
If it needs to be called when esp_wifi_scan_get_ap_records fails, then I wonder why this is not automatically done inside esp_wifi_scan_get_ap_records (at the end before returning with an error) or inside esp_wifi_scan_start (at the start). My confusion is in the sentence "when the [...] list fails". How can a list fail!? |
Could you help to explain the usage of esp_wifi_clear_ap_list() ? |
@freakyxue @igrr |
@freakyxue |
hi @AxelLin I'm sorry to reply until now. When the memory is insufficient, perform wifi scan., Failed to get wifi list. |
As I said this API is not used at all in current esp-idf. |
@xueyunfei998 |
scan_done_handler(uint16_t *sta_num, wifi_ap_record_t **ap_list_buffer_p)
Give an example from above. After failing to apply for memory in the callback function of scan done, need to call this interface to make clear the wifi list. If it is not clear, it will cause memory leakage. @AxelLin |
I don't get your point. The scan_done_handler in esp-idf has below prototype: |
Yes, that's what I mean. |
static void scan_done_handler() is a void function. |
Because the wifi list in wifi lib is also dynamically allocated, the dynamically allocated memory in wifi lib will be released after successfully getting the wifi list in scan done. If the Wifi List in scan done fails, the dynamically allocated memory in wifi lib will not be released, resulting in memory leakage. @AxelLin |
I think what you want to say is: |
In below testing code (modify from examples/wifi/scan), while (1) { |
I believe that "memory leak" is not the right description here. The found ap records occupy memory, but the IDF handles allocation and freeing correctly. |
hi @kriegste Your understanding is correct, but if the ssid memory in wifi lib is not released in time, there is no other opportunity to release this memory, which will lead to memory leakage. |
But that does not explain why there is no memory leakage found in #10693 (comment) . |
hi @AxelLin The following steps were followed to find the memory leak before 1 wifi scan Later, this bug was fixed,esp_wifi_clear_ap_list() was added, and bss info was cleared when wifi stop was performed. You can view this commit in wifi lib (845af059ecbb64cb175df20cd6e61d956fdf2a66)
You didn't find a memory leak because bss information will be re-released every time re-scan. |
Answers checklist.
General issue report
Hi,
in IDF 4.4.4 there is this new function called esp_wifi_clear_ap_list() ("Clear AP list found in last scan."). The description says: "When the obtained ap list fails,bss info must be cleared,otherwise it may cause memory leakage."
I do esp_wifi_scan_start() and in the event callback I use esp_wifi_scan_get_ap_num() and esp_wifi_scan_get_ap_records() to get the list of the scanned access points.
Exactly when do I need to use esp_wifi_clear_ap_list()? When the list fails? What does that mean? When esp_wifi_scan_get_ap_records() fails? There is no example.
The text was updated successfully, but these errors were encountered: