diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 5b937b4bffde..c8574131016c 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -257,8 +257,6 @@ retry: KASSERT(!timevalisset(&p->p_realtimer.it_value), ("realtime timer is still armed")); } - sigqueue_flush(&p->p_sigqueue); - sigqueue_flush(&td->td_sigqueue); PROC_UNLOCK(p); /* @@ -511,6 +509,14 @@ retry: PROC_LOCK(p->p_pptr); sx_xunlock(&proctree_lock); + /* + * The state PRS_ZOMBIE prevents other proesses from sending + * signal to the process, to avoid memory leak, we free memory + * for signal queue at the time when the state is set. + */ + sigqueue_flush(&p->p_sigqueue); + sigqueue_flush(&td->td_sigqueue); + /* * We have to wait until after acquiring all locks before * changing p_state. We need to avoid all possible context