service_traffic: Don't call pbuf_free when ethernet_input is Ok

This commit is contained in:
Stéphane Lenclud 2024-10-05 15:41:24 +02:00 committed by HiFiPhile
parent 6bfd024137
commit 3d3dcb1ee9

View File

@ -194,8 +194,13 @@ uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg) {
static void service_traffic(void) {
/* handle any packet received by tud_network_recv_cb() */
if (received_frame) {
ethernet_input(received_frame, &netif_data);
pbuf_free(received_frame);
// Surrender ownership of our pbuf unless there was an error
// Only call pbuf_free if not Ok else it will panic with "pbuf_free: p->ref > 0"
// or steal it from whatever took ownership of it with undefined consequences.
// See: https://savannah.nongnu.org/patch/index.php?10121
if (ethernet_input(received_frame, &netif_data)!=ERR_OK) {
pbuf_free(received_frame);
}
received_frame = NULL;
tud_network_recv_renew();
}