Module Name: src Committed By: martin Date: Thu Jun 20 18:22:48 UTC 2024
Modified Files: src/lib/libpthread [netbsd-10]: pthread.c Log Message: Pull up following revision(s) (requested by hannken in ticket #711): lib/libpthread/pthread.c: revision 1.185 Fix resource leak in pthread_create(). Pthread field "pt_lwpctl" must not be accessed after _lwp_exit() as the kernel may free it, attach it to another thread and change its "lc_curcpu". The "pthread__deadqueue" will fill up with pthreads with an invalid "pt_lwpctl" and allocated stack that never get reused. Replace the test "lc_curcpu == LWPCTL_CPU_EXITED" with test "_lwp_kill(newthread->pt_lid, 0) == -1 && errno == ESRCH" to make sure this thread has finished its _lwp_exit(). PR lib/57831 "Memory leaks in libpthread/libc" To generate a diff of this commit: cvs rdiff -u -r1.181.2.1 -r1.181.2.2 src/lib/libpthread/pthread.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libpthread/pthread.c diff -u src/lib/libpthread/pthread.c:1.181.2.1 src/lib/libpthread/pthread.c:1.181.2.2 --- src/lib/libpthread/pthread.c:1.181.2.1 Tue Nov 28 13:17:11 2023 +++ src/lib/libpthread/pthread.c Thu Jun 20 18:22:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.c,v 1.181.2.1 2023/11/28 13:17:11 martin Exp $ */ +/* $NetBSD: pthread.c,v 1.181.2.2 2024/06/20 18:22:47 martin Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020 @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread.c,v 1.181.2.1 2023/11/28 13:17:11 martin Exp $"); +__RCSID("$NetBSD: pthread.c,v 1.181.2.2 2024/06/20 18:22:47 martin Exp $"); #define __EXPOSE_STACK 1 @@ -462,9 +462,9 @@ pthread_create(pthread_t *thread, const if (!PTQ_EMPTY(&pthread__deadqueue)) { pthread_mutex_lock(&pthread__deadqueue_lock); PTQ_FOREACH(newthread, &pthread__deadqueue, pt_deadq) { - /* Still busily exiting, or finished? */ - if (newthread->pt_lwpctl->lc_curcpu == - LWPCTL_CPU_EXITED) + /* Still running? */ + if (_lwp_kill(newthread->pt_lid, 0) == -1 && + errno == ESRCH) break; } if (newthread)