summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2010-01-02 04:21:16 +0000
committerkrw <krw@openbsd.org>2010-01-02 04:21:16 +0000
commitd60fc4a49ba5bfd05a3b09e715a328032ca8a26c (patch)
tree4f19ae42780699a1e61c5605aae297d2b13c6448
parentcomplete the sync to 1.9.15-pre2: mostly minor fixes (diff)
downloadwireguard-openbsd-d60fc4a49ba5bfd05a3b09e715a328032ca8a26c.tar.xz
wireguard-openbsd-d60fc4a49ba5bfd05a3b09e715a328032ca8a26c.zip
Eliminate all uses of dmalloc() where the returned pointer
is checked for NULL and a specific error/warning issued. Add two such manual warning/error checks and kill those dmalloc calls. And then there were none, so kill dmalloc(). Whew.
-rw-r--r--usr.sbin/dhcpd/alloc.c26
-rw-r--r--usr.sbin/dhcpd/confpars.c5
-rw-r--r--usr.sbin/dhcpd/dhcp.c4
-rw-r--r--usr.sbin/dhcpd/dhcpd.h4
-rw-r--r--usr.sbin/dhcpd/dispatch.c5
-rw-r--r--usr.sbin/dhcpd/options.c8
-rw-r--r--usr.sbin/dhcpd/tree.c17
7 files changed, 32 insertions, 37 deletions
diff --git a/usr.sbin/dhcpd/alloc.c b/usr.sbin/dhcpd/alloc.c
index f3306f87cb2..6b8f0069738 100644
--- a/usr.sbin/dhcpd/alloc.c
+++ b/usr.sbin/dhcpd/alloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: alloc.c,v 1.11 2010/01/01 20:46:19 krw Exp $ */
+/* $OpenBSD: alloc.c,v 1.12 2010/01/02 04:21:16 krw Exp $ */
/* Memory allocation... */
@@ -43,17 +43,6 @@
#include "dhcpd.h"
struct lease_state *free_lease_states;
-
-void *
-dmalloc(int size, char *name)
-{
- void *foo = calloc(size, sizeof(char));
-
- if (!foo)
- warning("No memory for %s.", name);
- return (foo);
-}
-
struct tree_cache *free_tree_caches;
struct tree_cache *
@@ -65,7 +54,7 @@ new_tree_cache(char *name)
rval = free_tree_caches;
free_tree_caches = (struct tree_cache *)(rval->value);
} else {
- rval = dmalloc(sizeof(struct tree_cache), name);
+ rval = calloc(1, sizeof(struct tree_cache));
if (!rval)
error("unable to allocate tree cache for %s.", name);
}
@@ -86,10 +75,13 @@ new_lease_state(char *name)
if (free_lease_states) {
rval = free_lease_states;
- free_lease_states =
- (struct lease_state *)(free_lease_states->next);
- } else
- rval = dmalloc (sizeof (struct lease_state), name);
+ free_lease_states = free_lease_states->next;
+ } else {
+ rval = calloc(1, sizeof(struct lease_state));
+ if (!rval)
+ error("unable to allocate lease state for %s.", name);
+ }
+
return (rval);
}
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index 98ad39c3ae3..f53db1c321b 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confpars.c,v 1.17 2010/01/01 08:02:34 krw Exp $ */
+/* $OpenBSD: confpars.c,v 1.18 2010/01/02 04:21:16 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
@@ -515,8 +515,7 @@ void parse_host_declaration(cfile, group)
if (!name)
return;
- host = (struct host_decl *)dmalloc(sizeof (struct host_decl),
- "parse_host_declaration");
+ host = calloc(1, sizeof (struct host_decl));
if (!host)
error("can't allocate host decl struct %s.", name);
diff --git a/usr.sbin/dhcpd/dhcp.c b/usr.sbin/dhcpd/dhcp.c
index 1bb004e2674..720e8494362 100644
--- a/usr.sbin/dhcpd/dhcp.c
+++ b/usr.sbin/dhcpd/dhcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.c,v 1.29 2010/01/01 20:46:19 krw Exp $ */
+/* $OpenBSD: dhcp.c,v 1.30 2010/01/02 04:21:16 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -951,7 +951,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
/* Save the parameter request list if there is one. */
i = DHO_DHCP_PARAMETER_REQUEST_LIST;
if (packet->options[i].data) {
- state->prl = dmalloc(packet->options[i].len, "ack_lease: prl");
+ state->prl = calloc(1, packet->options[i].len);
if (!state->prl)
warning("no memory for parameter request list");
else {
diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h
index e9cca329792..2614f73e245 100644
--- a/usr.sbin/dhcpd/dhcpd.h
+++ b/usr.sbin/dhcpd/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.43 2010/01/01 20:30:25 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.44 2010/01/02 04:21:16 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -602,8 +602,6 @@ struct group *clone_group(struct group *, char *);
void write_leases(void);
/* alloc.c */
-void * dmalloc(int, char *);
-void dfree(void *, char *);
struct tree_cache *new_tree_cache(char *);
struct lease_state *new_lease_state(char *);
void free_lease_state(struct lease_state *, char *);
diff --git a/usr.sbin/dhcpd/dispatch.c b/usr.sbin/dhcpd/dispatch.c
index b33502af8bd..dae45e2713e 100644
--- a/usr.sbin/dhcpd/dispatch.c
+++ b/usr.sbin/dhcpd/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.24 2008/09/15 20:38:17 claudio Exp $ */
+/* $OpenBSD: dispatch.c,v 1.25 2010/01/02 04:21:16 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -109,8 +109,7 @@ discover_interfaces(void)
/* If there isn't already an interface by this name,
allocate one. */
if (tmp == NULL) {
- tmp = ((struct interface_info *)dmalloc(sizeof *tmp,
- "discover_interfaces"));
+ tmp = calloc(1, sizeof *tmp);
if (!tmp)
error("Insufficient memory to %s %s",
"record interface", ifa->ifa_name);
diff --git a/usr.sbin/dhcpd/options.c b/usr.sbin/dhcpd/options.c
index 4f008fb3cae..a42c688e466 100644
--- a/usr.sbin/dhcpd/options.c
+++ b/usr.sbin/dhcpd/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.25 2010/01/01 20:46:20 krw Exp $ */
+/* $OpenBSD: options.c,v 1.26 2010/01/02 04:21:16 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -159,7 +159,8 @@ parse_option_buffer(struct packet *packet,
* space for it and copy it there.
*/
if (!packet->options[code].data) {
- if (!(t = dmalloc(len + 1, "parse_option_buffer")))
+ t = calloc(1, len + 1);
+ if (!t)
error("Can't allocate storage for option %s.",
dhcp_options[code].name);
/*
@@ -176,8 +177,7 @@ parse_option_buffer(struct packet *packet,
* we last saw. This is really only required
* for clients, but what the heck...
*/
- t = dmalloc(len + packet->options[code].len + 1,
- "parse_option_buffer");
+ t = calloc(1, len + packet->options[code].len + 1);
if (!t)
error("Can't expand storage for option %s.",
dhcp_options[code].name);
diff --git a/usr.sbin/dhcpd/tree.c b/usr.sbin/dhcpd/tree.c
index 8d9614bab5e..02526992bb5 100644
--- a/usr.sbin/dhcpd/tree.c
+++ b/usr.sbin/dhcpd/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.14 2010/01/01 20:46:20 krw Exp $ */
+/* $OpenBSD: tree.c,v 1.15 2010/01/02 04:21:16 krw Exp $ */
/* Routines for manipulating parse trees... */
@@ -49,7 +49,9 @@ static void do_data_copy(int *, unsigned char **, int *, unsigned char *, int);
pair
cons(caddr_t car, pair cdr)
{
- pair foo = (pair)dmalloc(sizeof *foo, "cons");
+ pair foo;
+
+ foo = calloc(1, sizeof *foo);
if (!foo)
error("no memory for cons.");
foo->car = car;
@@ -109,8 +111,10 @@ tree_concat(struct tree *left, struct tree *right)
/* If both trees are constant, combine them. */
if (left->op == TREE_CONST && right->op == TREE_CONST) {
- unsigned char *buf = dmalloc(left->data.const_val.len
- + right->data.const_val.len, "tree_concat");
+ unsigned char *buf;
+
+ buf = calloc(1, left->data.const_val.len
+ + right->data.const_val.len);
if (!buf)
error("No memory to concatenate constants.");
@@ -188,8 +192,11 @@ tree_evaluate(struct tree_cache *tree_cache)
* If we can't allocate more memory, return with what we
* have (maybe nothing).
*/
- if (!(bp = (unsigned char *)dmalloc(bufix, "tree_evaluate")))
+ bp = calloc(1, bufix);
+ if (!bp) {
+ warning("no more memory for option data");
return 0;
+ }
/* Record the change in conditions... */
bc = bufix;