Skip to content
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

Blufi example init and deinit memory leak (IDFGH-14055) #14874

Closed
3 tasks done
josthlee opened this issue Nov 12, 2024 · 3 comments
Closed
3 tasks done

Blufi example init and deinit memory leak (IDFGH-14055) #14874

josthlee opened this issue Nov 12, 2024 · 3 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Status: In Progress Work is in progress Type: Bug bugs in IDF

Comments

@josthlee
Copy link

josthlee commented Nov 12, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.4-dev-4076-gce6085349f

Espressif SoC revision.

ESP32-C6 (QFN40) (revision v0.0)

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

None

Power Supply used.

USB

What is the expected behavior?

TL;DR is that I use esp_blufi_host_init and esp_blufi_host_deinit to start and stop NIMBLE blufi with CONFIG_BT_NIMBLE_ENABLED. However, it leaks 272 bytes every time with an init and deinit.

What is the actual behavior?

The root cause is the os_msys_get in esp_blufi.c line 226 and 234 and it never frees the allocated memory in deinit function.

Steps to reproduce.

I just add a workaround myself in components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c:: bluesp_blufi_btc_deinit since the variables are file scoped in esp_blufi.c and I hope you can patch it in a proper place.

void esp_blufi_btc_deinit(void)
{           
                
    int i = 0;  
    const struct ble_gatt_svc_def *svc;
    const struct ble_gatt_chr_def *chr;
    const struct ble_gatt_dsc_def *dsc;
                
    for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) {
        for (chr = svc->characteristics; chr && chr->uuid; chr++) {
            os_mbuf_free(gatt_values[i].buf);
            ++i;
            
            for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) {
                os_mbuf_free(gatt_values[i].buf);
                ++i;
            }
        }       
    }           
            
    btc_deinit();
} 

Debug Logs.

No response

More Information.

No response

@josthlee josthlee added the Type: Bug bugs in IDF label Nov 12, 2024
@github-actions github-actions bot changed the title Blufi example init and deinit memory leak Blufi example init and deinit memory leak (IDFGH-14055) Nov 12, 2024
@espressif-bot espressif-bot added Status: Opened Issue is new Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Nov 12, 2024
@strange969
Copy link
Collaborator

Hi @josthlee,

Thank you for bringing up this issue. I have looked into it and implemented the necessary code for deinitialization. I’m attaching the patch files for the IDF and NimBLE changes.

Please apply these patches to your repository. If you encounter any issues or need further assistance, feel free to let me know.

blufi_memory_leak_changes.zip

@josthlee
Copy link
Author

Hi @josthlee,

Thank you for bringing up this issue. I have looked into it and implemented the necessary code for deinitialization. I’m attaching the patch files for the IDF and NimBLE changes.

Please apply these patches to your repository. If you encounter any issues or need further assistance, feel free to let me know.

blufi_memory_leak_changes.zip

Noted and thank you. I will try the patch and then get back to you!

@josthlee
Copy link
Author

Thank you and I think I don't have any issue on this now. Will then close the issue, thanks!

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally Status: Selected for Development Issue is selected for development Status: In Progress Work is in progress and removed Status: In Progress Work is in progress Status: Done Issue is done internally Status: Selected for Development Issue is selected for development Resolution: Done Issue is done internally labels Nov 27, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally labels Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Status: In Progress Work is in progress Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants