diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-04-14 20:22:28 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-04-14 20:22:28 +0000 |
commit | 870c6104a921f8c58c7615b964d078d667429624 (patch) | |
tree | 745d2109144748b7a3f86ede5b4434b70bedf84d | |
parent | fe4328a186b83ec951ca7665dd3447927cb8a587 (diff) |
get rif of the few dmalloc/dfree occurances that were left
-rw-r--r-- | sbin/dhclient/alloc.c | 35 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/options.c | 12 | ||||
-rw-r--r-- | sbin/dhclient/tree.c | 21 |
4 files changed, 20 insertions, 52 deletions
diff --git a/sbin/dhclient/alloc.c b/sbin/dhclient/alloc.c index ce643ff060e..3301035aabf 100644 --- a/sbin/dhclient/alloc.c +++ b/sbin/dhclient/alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc.c,v 1.6 2004/04/14 20:15:47 henning Exp $ */ +/* $OpenBSD: alloc.c,v 1.7 2004/04/14 20:22:27 henning Exp $ */ /* Memory allocation... */ @@ -42,35 +42,12 @@ #include "dhcpd.h" -struct dhcp_packet *dhcp_free_list; -struct packet *packet_free_list; - -void * -dmalloc(int size, char *name) -{ - void *foo = calloc(size, sizeof(char)); - - if (!foo) - warn("No memory for %s.", name); - return (foo); -} - -void -dfree(void *ptr, char *name) -{ - if (!ptr) { - warn("dfree %s: free on null pointer.", name); - return; - } - free(ptr); -} - struct string_list * new_string_list(size_t size, char * name) { struct string_list *rval; - rval = dmalloc(sizeof(struct string_list) + size, name); + rval = calloc(1, sizeof(struct string_list) + size); if (rval != NULL) rval->string = ((char *)rval) + sizeof(struct string_list); return (rval); @@ -81,9 +58,9 @@ new_hash_table(int count, char *name) { struct hash_table *rval; - rval = dmalloc(sizeof(struct hash_table) - + rval = calloc(1, sizeof(struct hash_table) - (DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)) + - (count * sizeof(struct hash_bucket *)), name); + (count * sizeof(struct hash_bucket *))); if (rval == NULL) return (NULL); rval->hash_count = count; @@ -93,7 +70,7 @@ new_hash_table(int count, char *name) struct hash_bucket * new_hash_bucket(char *name) { - struct hash_bucket *rval = dmalloc(sizeof(struct hash_bucket), name); + struct hash_bucket *rval = calloc(1, sizeof(struct hash_bucket)); return (rval); } @@ -101,5 +78,5 @@ new_hash_bucket(char *name) void free_hash_bucket(struct hash_bucket *ptr, char *name) { - dfree(ptr, name); + free(ptr); } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index bdde0e508a0..f2533d81feb 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.27 2004/04/14 20:15:47 henning Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.28 2004/04/14 20:22:27 henning Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -290,8 +290,6 @@ struct dns_host_entry *enter_dns_host(char *); pair cons(caddr_t, pair); /* alloc.c */ -void *dmalloc(int, char *); -void dfree(void *, char *); struct string_list *new_string_list(size_t size, char * name); struct hash_table *new_hash_table(int, char *); struct hash_bucket *new_hash_bucket(char *); diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index ad3d70489b2..61382e89c37 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.7 2004/03/02 18:49:21 deraadt Exp $ */ +/* $OpenBSD: options.c,v 1.8 2004/04/14 20:22:27 henning Exp $ */ /* DHCP options parsing and reassembly. */ @@ -157,7 +157,7 @@ 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"))) + if (!(t = calloc(1, len + 1))) error("Can't allocate storage for option %s.", dhcp_options[code].name); /* @@ -174,8 +174,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); @@ -185,8 +184,7 @@ parse_option_buffer(struct packet *packet, &s[2], len); packet->options[code].len += len; t[packet->options[code].len] = 0; - dfree(packet->options[code].data, - "parse_option_buffer"); + free(packet->options[code].data); packet->options[code].data = t; } s += len + 2; @@ -734,5 +732,5 @@ do_packet(struct interface_info *interface, struct dhcp_packet *packet, /* Free the data associated with the options. */ for (i = 0; i < 256; i++) if (tp.options[i].len && tp.options[i].data) - dfree(tp.options[i].data, "do_packet"); + free(tp.options[i].data); } diff --git a/sbin/dhclient/tree.c b/sbin/dhclient/tree.c index 0a57087a0d3..88c2369b76f 100644 --- a/sbin/dhclient/tree.c +++ b/sbin/dhclient/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.9 2004/02/24 17:02:40 henning Exp $ */ +/* $OpenBSD: tree.c,v 1.10 2004/04/14 20:22:27 henning Exp $ */ /* Routines for manipulating parse trees... */ @@ -54,7 +54,7 @@ static void do_data_copy(int *, unsigned char **, int *, unsigned char *, pair cons(caddr_t car, pair cdr) { - pair foo = dmalloc(sizeof(*foo), "cons"); + pair foo = calloc(1, sizeof(*foo)); if (!foo) error("no memory for cons."); foo->car = car; @@ -68,14 +68,10 @@ enter_dns_host(char *name) struct dns_host_entry *dh; int len = strlen(name) + 1; - if (!(dh = dmalloc(sizeof(struct dns_host_entry), "enter_dns_host")) - || !(dh->hostname = dmalloc(len, "enter_dns_host"))) + if (!(dh = calloc(1, sizeof(struct dns_host_entry))) + || !(dh->hostname = calloc(1, len))) error("Can't allocate space for new host."); strlcpy(dh->hostname, name, len); - dh->data = NULL; - dh->data_len = 0; - dh->buf_len = 0; - dh->timeout = 0; return (dh); } @@ -107,7 +103,7 @@ tree_evaluate(struct tree_cache *tree_cache) * If we can't allocate more memory, return with what we have * (maybe nothing). */ - if (!(bp = dmalloc(bufix, "tree_evaluate"))) + if (!(bp = calloc(1, bufix))) return (0); /* Record the change in conditions... */ @@ -125,8 +121,7 @@ tree_evaluate(struct tree_cache *tree_cache) * Free the old buffer if needed, then store the new buffer * location and size and return. */ - if (tree_cache->value) - dfree(tree_cache->value, "tree_evaluate"); + free(tree_cache->value); tree_cache->value = bp; tree_cache->len = bufix; tree_cache->buf_size = bc; @@ -219,7 +214,7 @@ do_host_lookup(int *bufix, unsigned char **bufp, int *bufcount, /* Do we need to allocate more memory? */ new_len = i * h->h_length; if (dns->buf_len < i) { - unsigned char *buf = dmalloc(new_len, "do_host_lookup"); + unsigned char *buf = calloc(1, new_len); /* If we didn't get more memory, use what we have. */ if (!buf) { new_len = dns->buf_len; @@ -229,7 +224,7 @@ do_host_lookup(int *bufix, unsigned char **bufp, int *bufcount, } } else { if (dns->data) - dfree(dns->data, "do_host_lookup"); + free(dns->data); dns->data = buf; dns->buf_len = new_len; } |