diff options
author | 2018-03-30 17:33:54 +0000 | |
---|---|---|
committer | 2018-03-30 17:33:54 +0000 | |
commit | 2ab04138deb0da601dd7fca4b7dd30a77760dfed (patch) | |
tree | def43548b491548797ef4f18c9287b66819de630 | |
parent | Remove a premature newline print. A later print already does it and (diff) | |
download | wireguard-openbsd-2ab04138deb0da601dd7fca4b7dd30a77760dfed.tar.xz wireguard-openbsd-2ab04138deb0da601dd7fca4b7dd30a77760dfed.zip |
Store the allocation size in inpcbhead for free().
OK visa@
-rw-r--r-- | sys/netinet/in_pcb.c | 21 | ||||
-rw-r--r-- | sys/netinet/in_pcb.h | 4 |
2 files changed, 14 insertions, 11 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 45a274206a1..ab59d6abab5 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.228 2018/02/19 08:59:53 mpi Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.229 2018/03/30 17:33:54 dhill Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -206,6 +206,7 @@ in_pcbinit(struct inpcbtable *table, int hashsize) if (table->inpt_lhashtbl == NULL) panic("in_pcbinit: hashinit failed for lport"); table->inpt_count = 0; + table->inpt_size = hashsize; arc4random_buf(&table->inpt_key, sizeof(table->inpt_key)); } @@ -998,32 +999,34 @@ int in_pcbresize(struct inpcbtable *table, int hashsize) { u_long nhash, nlhash; + int osize; void *nhashtbl, *nlhashtbl, *ohashtbl, *olhashtbl; struct inpcb *inp0, *inp1; ohashtbl = table->inpt_hashtbl; olhashtbl = table->inpt_lhashtbl; + osize = table->inpt_size; nhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, &nhash); + if (nhashtbl == NULL) + return ENOBUFS; nlhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, &nlhash); - if (nhashtbl == NULL || nlhashtbl == NULL) { - if (nhashtbl != NULL) - free(nhashtbl, M_PCB, 0); - if (nlhashtbl != NULL) - free(nlhashtbl, M_PCB, 0); - return (ENOBUFS); + if (nlhashtbl == NULL) { + hashfree(nhashtbl, hashsize, M_PCB); + return ENOBUFS; } table->inpt_hashtbl = nhashtbl; table->inpt_lhashtbl = nlhashtbl; table->inpt_hash = nhash; table->inpt_lhash = nlhash; + table->inpt_size = hashsize; arc4random_buf(&table->inpt_key, sizeof(table->inpt_key)); TAILQ_FOREACH_SAFE(inp0, &table->inpt_queue, inp_queue, inp1) { in_pcbrehash(inp0); } - free(ohashtbl, M_PCB, 0); - free(olhashtbl, M_PCB, 0); + hashfree(ohashtbl, osize, M_PCB); + hashfree(olhashtbl, osize, M_PCB); return (0); } diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index fdddaba3df3..bf5a3c97300 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.106 2017/12/01 10:33:33 bluhm Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.107 2018/03/30 17:33:54 dhill Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -152,7 +152,7 @@ struct inpcbtable { struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl; SIPHASH_KEY inpt_key; u_long inpt_hash, inpt_lhash; - int inpt_count; + int inpt_count, inpt_size; }; /* flags in inp_flags: */ |