Module Name: src Committed By: ad Date: Sun Jan 26 19:08:09 UTC 2020
Modified Files: src/sys/compat/netbsd32: netbsd32_lwp.c src/sys/kern: sys_lwp.c Log Message: Correction to previous: don't leak newuc if copyout() fails. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/compat/netbsd32/netbsd32_lwp.c cvs rdiff -u -r1.72 -r1.73 src/sys/kern/sys_lwp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/netbsd32/netbsd32_lwp.c diff -u src/sys/compat/netbsd32/netbsd32_lwp.c:1.20 src/sys/compat/netbsd32/netbsd32_lwp.c:1.21 --- src/sys/compat/netbsd32/netbsd32_lwp.c:1.20 Sat Jan 25 15:41:52 2020 +++ src/sys/compat/netbsd32/netbsd32_lwp.c Sun Jan 26 19:08:09 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_lwp.c,v 1.20 2020/01/25 15:41:52 ad Exp $ */ +/* $NetBSD: netbsd32_lwp.c,v 1.21 2020/01/26 19:08:09 ad Exp $ */ /* * Copyright (c) 2005, 2006, 2007, 2020 The NetBSD Foundation. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.20 2020/01/25 15:41:52 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.21 2020/01/26 19:08:09 ad Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -84,12 +84,11 @@ netbsd32__lwp_create(struct lwp *l, cons error = copyout(&l2->l_lid, SCARG_P32(uap, new_lwp), sizeof(l2->l_lid)); - if (error != 0) - lwp_exit(l2); - else + if (error == 0) { lwp_start(l2, SCARG(uap, flags)); - return error; - + return 0; + } + lwp_exit(l2); fail: kmem_free(newuc, sizeof(ucontext_t)); return error; Index: src/sys/kern/sys_lwp.c diff -u src/sys/kern/sys_lwp.c:1.72 src/sys/kern/sys_lwp.c:1.73 --- src/sys/kern/sys_lwp.c:1.72 Sat Jan 25 15:41:52 2020 +++ src/sys/kern/sys_lwp.c Sun Jan 26 19:08:09 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_lwp.c,v 1.72 2020/01/25 15:41:52 ad Exp $ */ +/* $NetBSD: sys_lwp.c,v 1.73 2020/01/26 19:08:09 ad Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.72 2020/01/25 15:41:52 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.73 2020/01/26 19:08:09 ad Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -156,12 +156,11 @@ sys__lwp_create(struct lwp *l, const str goto fail; error = copyout(&l2->l_lid, SCARG(uap, new_lwp), sizeof(l2->l_lid)); - if (error != 0) - lwp_exit(l2); - else + if (error == 0) { lwp_start(l2, SCARG(uap, flags)); - return error; - + return 0; + } + lwp_exit(l2); fail: kmem_free(newuc, sizeof(ucontext_t)); return error;