3
Memory allocation... */
6
* Copyright (c) 1995, 1996, 1998 The Internet Software Consortium.
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
* 3. Neither the name of The Internet Software Consortium nor the names
19
* of its contributors may be used to endorse or promote products derived
20
* from this software without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
* DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36
* This software has been written for the Internet Software Consortium
37
* by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
38
* Enterprises. To learn more about the Internet Software Consortium,
39
* see ``http://www.vix.com/isc''. To learn more about Vixie
40
* Enterprises, see ``http://www.vix.com''.
44
static char copyright[] =
45
"$Id: alloc.c,v 1.13.2.2 1999/03/26 16:39:36 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
50
struct dhcp_packet *dhcp_free_list;
51
struct packet *packet_free_list;
53
VOIDPTR dmalloc (size, name)
57
VOIDPTR foo = (VOIDPTR)malloc (size);
59
warn ("No memory for %s.", name);
61
memset (foo, 0, size);
65
void dfree (ptr, name)
70
warn ("dfree %s: free on null pointer.", name);
76
struct packet *new_packet (name)
80
rval = (struct packet *)dmalloc (sizeof (struct packet), name);
84
struct dhcp_packet *new_dhcp_packet (name)
87
struct dhcp_packet *rval;
88
rval = (struct dhcp_packet *)dmalloc (sizeof (struct dhcp_packet),
93
struct tree *new_tree (name)
96
struct tree *rval = dmalloc (sizeof (struct tree), name);
100
struct tree_cache *free_tree_caches;
102
struct tree_cache *new_tree_cache (name)
105
struct tree_cache *rval;
107
if (free_tree_caches) {
108
rval = free_tree_caches;
110
(struct tree_cache *)(rval -> value);
112
rval = dmalloc (sizeof (struct tree_cache), name);
114
error ("unable to allocate tree cache for %s.", name);
119
struct hash_table *new_hash_table (count, name)
123
struct hash_table *rval = dmalloc (sizeof (struct hash_table)
125
* sizeof (struct hash_bucket *))
127
* sizeof (struct hash_bucket *)),
129
rval -> hash_count = count;
133
struct hash_bucket *new_hash_bucket (name)
136
struct hash_bucket *rval = dmalloc (sizeof (struct hash_bucket), name);
140
struct lease *new_leases (n, name)
144
struct lease *rval = dmalloc (n * sizeof (struct lease), name);
148
struct lease *new_lease (name)
151
struct lease *rval = dmalloc (sizeof (struct lease), name);
155
struct subnet *new_subnet (name)
158
struct subnet *rval = dmalloc (sizeof (struct subnet), name);
162
struct class *new_class (name)
165
struct class *rval = dmalloc (sizeof (struct class), name);
169
struct shared_network *new_shared_network (name)
172
struct shared_network *rval =
173
dmalloc (sizeof (struct shared_network), name);
177
struct group *new_group (name)
181
dmalloc (sizeof (struct group), name);
185
struct protocol *new_protocol (name)
188
struct protocol *rval = dmalloc (sizeof (struct protocol), name);
192
struct lease_state *free_lease_states;
194
struct lease_state *new_lease_state (name)
197
struct lease_state *rval;
199
if (free_lease_states) {
200
rval = free_lease_states;
202
(struct lease_state *)(free_lease_states -> next);
204
rval = dmalloc (sizeof (struct lease_state), name);
209
struct domain_search_list *new_domain_search_list (name)
212
struct domain_search_list *rval =
213
dmalloc (sizeof (struct domain_search_list), name);
217
struct name_server *new_name_server (name)
220
struct name_server *rval =
221
dmalloc (sizeof (struct name_server), name);
225
void free_name_server (ptr, name)
226
struct name_server *ptr;
229
dfree ((VOIDPTR)ptr, name);
232
void free_domain_search_list (ptr, name)
233
struct domain_search_list *ptr;
236
dfree ((VOIDPTR)ptr, name);
239
void free_lease_state (ptr, name)
240
struct lease_state *ptr;
244
dfree (ptr -> prl, name);
245
ptr -> next = free_lease_states;
246
free_lease_states = ptr;
249
void free_protocol (ptr, name)
250
struct protocol *ptr;
253
dfree ((VOIDPTR)ptr, name);
256
void free_group (ptr, name)
260
dfree ((VOIDPTR)ptr, name);
263
void free_shared_network (ptr, name)
264
struct shared_network *ptr;
267
dfree ((VOIDPTR)ptr, name);
270
void free_class (ptr, name)
274
dfree ((VOIDPTR)ptr, name);
277
void free_subnet (ptr, name)
281
dfree ((VOIDPTR)ptr, name);
284
void free_lease (ptr, name)
288
dfree ((VOIDPTR)ptr, name);
291
void free_hash_bucket (ptr, name)
292
struct hash_bucket *ptr;
295
dfree ((VOIDPTR)ptr, name);
298
void free_hash_table (ptr, name)
299
struct hash_table *ptr;
302
dfree ((VOIDPTR)ptr, name);
305
void free_tree_cache (ptr, name)
306
struct tree_cache *ptr;
309
ptr -> value = (unsigned char *)free_tree_caches;
310
free_tree_caches = ptr;
313
void free_packet (ptr, name)
317
dfree ((VOIDPTR)ptr, name);
320
void free_dhcp_packet (ptr, name)
321
struct dhcp_packet *ptr;
324
dfree ((VOIDPTR)ptr, name);
327
void free_tree (ptr, name)
331
dfree ((VOIDPTR)ptr, name);