From d9770d2c5fd3622348da99aeb2750f1b51e2d309 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 28 Feb 2018 22:48:56 +0100 Subject: [PATCH] tcpip_thread: TCPIP_MSG_INPKT: free input pbufs if the input function returns an error This simply wasn't the case until 6LoWPAN. However, since tcpip_input is like this, we should stay with that pattern. Adapted documentation in netif.h Signed-off-by: goldsimon --- src/api/tcpip.c | 4 +++- src/include/lwip/netif.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 1740861c..743553a5 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -171,7 +171,9 @@ tcpip_thread_handle_msg(struct tcpip_msg *msg) #if !LWIP_TCPIP_CORE_LOCKING_INPUT case TCPIP_MSG_INPKT: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg)); - msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif); + if (msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif) != ERR_OK) { + pbuf_free(msg->msg.inp.p); + } memp_free(MEMP_TCPIP_MSG_INPKT, msg); break; #endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 59d518c9..fba4fd7d 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -171,6 +171,9 @@ typedef err_t (*netif_init_fn)(struct netif *netif); * * @param p The received packet, copied into a pbuf * @param inp The netif which received the packet + * @return ERR_OK if the packet was handled + * != ERR_OK is the packet was NOT handled, in this case, the caller has + * to free the pbuf */ typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);