diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-06-12 14:56:22 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-06-12 14:56:22 +0000 |
commit | 5723e8eb7cbab958abaa57baea7f003783831dd7 (patch) | |
tree | 5a9b38a1e7fde0dbcb8ca1f0f952d8ebe9891aac /sys/kern/subr_pool.c | |
parent | 8a75122525b4e8885b5a5f5faf2352d89fff9cfb (diff) |
rework pool_get() a bit so that if you call if with a constructor set
*and* PR_ZERO in flags, you will no longer zero our your nicely
constructed object.
Instead, now if you have a contructor set, and you set PR_ZERO, you will
panic (it's invalid due to how constructor work).
ok miod@ deraadt@ on earlier versions of the diff. ok tedu@ after he
pointed out a couple of places I messed up.
Problem initally noticed by ariane@ a while ago.
Diffstat (limited to 'sys/kern/subr_pool.c')
-rw-r--r-- | sys/kern/subr_pool.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index 0f155c0b12d..aa0d1213a81 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.83 2009/06/04 18:48:54 deraadt Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.84 2009/06/12 14:56:21 oga Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -458,17 +458,24 @@ pool_get(struct pool *pp, int flags) mtx_enter(&pp->pr_mtx); v = pool_do_get(pp, flags); mtx_leave(&pp->pr_mtx); - if (v && pp->pr_ctor && pp->pr_ctor(pp->pr_arg, v, flags)) { - mtx_enter(&pp->pr_mtx); - pool_do_put(pp, v); - mtx_leave(&pp->pr_mtx); - v = NULL; - } - if (v) { - pp->pr_nget++; + if (v == NULL) + return (v); + + if (pp->pr_ctor) { + if (flags & PR_ZERO) + panic("pool_get: PR_ZERO when ctor set"); + if (pp->pr_ctor(pp->pr_arg, v, flags)) { + mtx_enter(&pp->pr_mtx); + pool_do_put(pp, v); + mtx_leave(&pp->pr_mtx); + v = NULL; + } + } else { if (flags & PR_ZERO) memset(v, 0, pp->pr_size); } + if (v != NULL) + pp->pr_nget++; return (v); } |