From 19d3e47dca171551d1dd724863d05b5a0b74e34f Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Mon, 16 Nov 2020 03:12:21 +0000 Subject: [PATCH] select: call seltdfini on process and thread exit Since thread_zone is marked NOFREE the thread_fini callback is never executed, meaning memory allocated by seltdinit is never released. Adding the call to thread_dtor is not sufficient as exiting processes cache the main thread. --- sys/kern/kern_exit.c | 1 + sys/kern/kern_thread.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 4df7842ddc0e..c81878742b75 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -355,6 +355,7 @@ exit1(struct thread *td, int rval, int signo) PROC_UNLOCK(p); umtx_thread_exit(td); + seltdfini(td); /* * Reset any sigio structures pointing to us as a result of diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index a14c881e4cdd..654d3a6c3b05 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -329,6 +329,7 @@ thread_ctor(void *mem, int size, void *arg, int flags) audit_thread_alloc(td); #endif umtx_thread_alloc(td); + MPASS(td->td_sel == NULL); return (0); } @@ -369,6 +370,7 @@ thread_dtor(void *mem, int size, void *arg) osd_thread_exit(td); td_softdep_cleanup(td); MPASS(td->td_su == NULL); + seltdfini(td); } /* @@ -405,7 +407,7 @@ thread_fini(void *mem, int size) turnstile_free(td->td_turnstile); sleepq_free(td->td_sleepqueue); umtx_thread_fini(td); - seltdfini(td); + MPASS(td->td_sel == NULL); } /*