diff --git a/sys/kern/kern_dmsg.c b/sys/kern/kern_dmsg.c index d6e90ee..92dc65f 100644 --- a/sys/kern/kern_dmsg.c +++ b/sys/kern/kern_dmsg.c @@ -306,6 +306,20 @@ kdmsg_iocom_uninit(kdmsg_iocom_t *iocom) kdmsg_state_drop(state); } + /* + * Both iocom threads are gone (or never existed). Nothing can + * transmit what is still queued on msgq (e.g. the LNK_PING + * allocated above to unstick the reader); drain the queue so + * those messages are freed instead of leaking with the iocom, + * mirroring the write-thread exit path (kdmsg_drain_msgq call + * at the head of the termination loop in kdmsg_iocom_thread_wr). + * + * uninit holds msglk exclusively, satisfying kdmsg_drain_msgq's + * locking requirement. + */ + iocom->flags |= KDMSG_IOCOMF_EXITNOACC; + kdmsg_drain_msgq(iocom); + /* * Drop communications descriptor */