git: 73b576abf509 - stable/15 - kthread: Fix a thread leak

Mark Johnston <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a74a1ca.45e52.160c9f17__28275.2426037163$1786028537$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=73b576abf509f1cb057954937dd2809a5ba7a2dc

commit 73b576abf509f1cb057954937dd2809a5ba7a2dc
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-07-24 20:04:45 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-08-06 12:52:28 +0000

    kthread: Fix a thread leak
    
    Fixes:          963629923308 ("kthread_add(): do not allow to attach the thread to a dead or dying process")
    Reviewed by:    kib
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D58433
    
    (cherry picked from commit c7917e72fe80e2e168b3812718b5fcd497c0e3b8)
---
 sys/kern/kern_kthread.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c
index cfe2dab2e05c..6650ab868f78 100644
--- a/sys/kern/kern_kthread.c
+++ b/sys/kern/kern_kthread.c
@@ -281,6 +281,7 @@ kthread_add1(void (*func)(void *), void *arg, struct proc *p,
 	PROC_LOCK(p);
 	if (p->p_state == PRS_ZOMBIE || (p->p_flag2 & P2_WEXIT) != 0) {
 		PROC_UNLOCK(p);
+		thread_free(newtd);
 		return (ESRCH);
 	}
 	oldtd = FIRST_THREAD_IN_PROC(p);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.