1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-26 06:53:52 +01:00

gnrc_netreg: drain mbox on unregister

If there are still messages in the mbox when gnrc_netreg_unregister()
is called, we must release the associated pktbuf snips, otherwise
they are leaked away forever.

E.g. `sock_udp_close()` was called without receiving all messages with
`sock_udp_recv()`.
This commit is contained in:
Benjamin Valentin 2022-05-29 22:39:24 +02:00
parent bf2d4808c4
commit bf5926283b

View File

@ -73,6 +73,16 @@ void gnrc_netreg_unregister(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
}
LL_DELETE(netreg[type], entry);
#if defined(MODULE_GNRC_NETAPI_MBOX)
/* drain packets still in the mbox */
if (entry->type == GNRC_NETREG_TYPE_MBOX) {
msg_t msg;
while (mbox_try_get(entry->target.mbox, &msg)) {
gnrc_pktbuf_release_error(msg.content.ptr, EBADF);
}
}
#endif
}
/**