Skip to content

esp_netif: retain RX pbuf free callback (IDFGH-17719)#18656

Open
dhimasardinata wants to merge 4 commits into
espressif:masterfrom
dhimasardinata:fix/esp-netif-pbuf-free-callback
Open

esp_netif: retain RX pbuf free callback (IDFGH-17719)#18656
dhimasardinata wants to merge 4 commits into
espressif:masterfrom
dhimasardinata:fix/esp-netif-pbuf-free-callback

Conversation

@dhimasardinata

Copy link
Copy Markdown
Contributor

Summary

  • Store the driver RX-buffer free callback and driver handle in each custom pbuf when it is allocated.
  • Keep delayed pbuf_free() independent from later esp_netif driver config teardown.
  • Add an esp_netif regression test that clears the driver config before freeing the custom pbuf.

Root cause

esp_pbuf_allocate() kept an esp_netif_t * inside the custom pbuf. If the netif driver config was cleared before a queued pbuf was drained, esp_pbuf_free() could later call through the cleared/stale esp_netif->driver_free_rx_buffer path.

Verification

  • git diff --check
  • idf.py -C examples/wifi/getting_started/station -B /tmp/espnetif_pbuf_station_build -D SDKCONFIG=/tmp/espnetif_pbuf_station_sdkconfig set-target esp32 build
  • idf.py -C components/esp_netif/test_apps/test_app_esp_netif -B /tmp/espnetif_test_app_build -D SDKCONFIG=/tmp/espnetif_test_app_sdkconfig set-target esp32 build

Refs espressif/arduino-esp32#12517

Store the driver RX-buffer free callback and driver handle inside each custom pbuf at allocation time. This keeps delayed pbuf_free() independent from later esp_netif driver config teardown.

Add an esp_netif regression test that clears the driver config before freeing a custom pbuf.
@github-actions github-actions Bot changed the title esp_netif: retain RX pbuf free callback esp_netif: retain RX pbuf free callback (IDFGH-17719) May 26, 2026
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 26, 2026
Comment thread components/esp_netif/lwip/netif/esp_pbuf_ref.c
Comment thread components/esp_netif/lwip/netif/esp_pbuf_ref.c
Comment thread components/esp_netif/lwip/netif/esp_pbuf_ref.c

@david-cermak david-cermak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

It makes sense to fix it this way, if there still might be some pbufs active after deleting netif. I'll think about how we could documented. but I think we can merge the fix. Thank you!

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable Resolution: Done Issue is done internally and removed Status: Opened Issue is new Resolution: NA Issue resolution is unavailable labels Jun 15, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants