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 <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-08-30 18:36:39 +08:00 committed by Xiang Xiao
parent 6dde42d79b
commit e10b546006

View File

@ -226,13 +226,16 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(void)
void udp_wrbuffer_release(FAR struct udp_wrbuffer_s *wrb) 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 /* To avoid deadlocks, we must following this ordering: Release the I/O
* buffer chain first, then the write buffer structure. * 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 */ /* Then free the write buffer structure */