summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-11-05 22:27:41 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-11-05 22:27:41 +0000
commit626bd68561948953b6314b6746c7cb236018aa56 (patch)
tree7604200f598685dfd63c8a06d79e6be5d06f2d9a
parentc3167b81c0130f1d9368dd541be1b133fe0b805b (diff)
need to move lock up to prevent more than one malloc. ok guenther
-rw-r--r--sys/kern/kern_malloc.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index cdd7ba5c884..eb400a2d9e5 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.120 2014/11/05 18:08:21 tedu Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.121 2014/11/05 22:27:40 tedu Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -572,7 +572,7 @@ sysctl_malloc(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
size_t newlen, struct proc *p)
{
struct kmembuckets kb;
- int i, siz;
+ int error, i, siz;
if (namelen != 2 && name[0] != KERN_MALLOC_BUCKETS &&
name[0] != KERN_MALLOC_KMEMNAMES)
@@ -611,13 +611,11 @@ sysctl_malloc(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
#endif
case KERN_MALLOC_KMEMNAMES:
#if defined(KMEMSTATS) || defined(DIAGNOSTIC) || defined(FFS_SOFTUPDATES)
+ error = rw_enter(&sysctl_kmemlock, RW_WRITE|RW_INTR);
+ if (error)
+ return (error);
if (memall == NULL) {
int totlen;
- int error;
-
- error = rw_enter(&sysctl_kmemlock, RW_WRITE|RW_INTR);
- if (error)
- return (error);
/* Figure out how large a buffer we need */
for (totlen = 0, i = 0; i < M_LAST; i++) {
@@ -641,8 +639,8 @@ sysctl_malloc(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
for (i = 0; i < totlen; i++)
if (memall[i] == ' ')
memall[i] = '_';
- rw_exit_write(&sysctl_kmemlock);
}
+ rw_exit_write(&sysctl_kmemlock);
return (sysctl_rdstring(oldp, oldlenp, newp, memall));
#else
return (EOPNOTSUPP);