From e10b54600665f6899bb6ff516c6ef6ac24a9f199 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 30 Aug 2021 18:36:39 +0800 Subject: [PATCH] net/udp: fix buffer release handling on failed buffer alloc Attempt to release write buffer on failed UDP write I/O buffer alloc and tryalloc failed to wrb->wb_iob assertion. Signed-off-by: chao.an --- net/udp/udp_wrbuffer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/udp/udp_wrbuffer.c b/net/udp/udp_wrbuffer.c index 076300d868..9e7b7c7fdb 100644 --- a/net/udp/udp_wrbuffer.c +++ b/net/udp/udp_wrbuffer.c @@ -226,13 +226,16 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(void) void udp_wrbuffer_release(FAR struct udp_wrbuffer_s *wrb) { - DEBUGASSERT(wrb && wrb->wb_iob); + DEBUGASSERT(wrb); /* To avoid deadlocks, we must following this ordering: Release the I/O * buffer chain first, then the write buffer structure. */ - iob_free_chain(wrb->wb_iob, IOBUSER_NET_UDP_WRITEBUFFER); + if (wrb->wb_iob) + { + iob_free_chain(wrb->wb_iob, IOBUSER_NET_UDP_WRITEBUFFER); + } /* Then free the write buffer structure */