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

Heap memory leak when using gpio_install_isr_service and gpio_uninstall_isr_service (IDFGH-14172) #14973

Closed
3 tasks done
MmdMi opened this issue Dec 3, 2024 · 2 comments
Closed
3 tasks done
Assignees
Labels
Awaiting Response awaiting a response from the author Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally

Comments

@MmdMi
Copy link

MmdMi commented Dec 3, 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.

General issue report

Title: Heap memory leak when using gpio_install_isr_service and gpio_uninstall_isr_service

Description:
I encountered a heap memory leak issue while testing the gpio_install_isr_service and gpio_uninstall_isr_service functions in my ESP-IDF project. When these functions are called, 16 bytes of heap memory remain unreleased, causing a memory leak.

Steps to reproduce:

  1. Call gpio_install_isr_service with default flags.
  2. Call gpio_uninstall_isr_service.
  3. Compare the heap size before and after using the following code snippet:
uint32_t start_heap = esp_get_free_heap_size();
ESP_ERROR_CHECK(gpio_install_isr_service(0));
gpio_uninstall_isr_service();
uint32_t end_heap = esp_get_free_heap_size();
ESP_LOGI(TAG, "Diff[%ld]", (start_heap - end_heap));

Observed behavior:
The output of the above code is:

I (459) test_heap: Diff[16]

Expected behavior:
After calling gpio_uninstall_isr_service, the heap memory should be fully released, and the difference should be 0.

ESP-IDF version:

  • ESP-IDF v5.3.1

Environment:

  • ESP32-WROOM-32 module
  • Platform: Ubuntu 24.04

Additional notes:
This issue might accumulate over time if the gpio_install_isr_service and gpio_uninstall_isr_service functions are used repeatedly in a long-running application, leading to eventual heap exhaustion.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 3, 2024
@github-actions github-actions bot changed the title Heap memory leak when using gpio_install_isr_service and gpio_uninstall_isr_service Heap memory leak when using gpio_install_isr_service and gpio_uninstall_isr_service (IDFGH-14172) Dec 3, 2024
@ESP-Marius
Copy link
Collaborator

The interrupt allocator will lazy allocate some descriptors, and these will be re-used when interrupts are freed.

So these 16 bytes you see here will be used again when someone allocates a new interrupt, repeatably calling gpio_install_isr_service will not cause issues or heap exhaustion.

@Alvin1Zhang
Copy link
Collaborator

@MmdMi Thanks for reporting, can you please help share if any further updates for the issue? Thanks.

@Alvin1Zhang Alvin1Zhang added the Awaiting Response awaiting a response from the author label Dec 26, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new labels Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Response awaiting a response from the author Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

4 participants