From 5723e8eb7cbab958abaa57baea7f003783831dd7 Mon Sep 17 00:00:00 2001 From: Owain Ainsworth Date: Fri, 12 Jun 2009 14:56:22 +0000 Subject: 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. --- sys/kern/subr_pool.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'sys') 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); } -- cgit v1.2.3