summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTed Lemon <source@isc.org>2001-01-25 08:18:37 +0000
committerTed Lemon <source@isc.org>2001-01-25 08:18:37 +0000
commitfe48fc2c852c5344139f92516681e7c4899b2ccb (patch)
tree1e2c94140cf7f6fe4f4b34fa88f7502477b455cf /common
parent1c44f6bd86d9e859379fc5c32f8ab6a945f064d1 (diff)
downloadisc-dhcp-fe48fc2c852c5344139f92516681e7c4899b2ccb.tar.gz
Add allocators for option_chain_head structure.
Diffstat (limited to 'common')
-rw-r--r--common/alloc.c116
1 files changed, 115 insertions, 1 deletions
diff --git a/common/alloc.c b/common/alloc.c
index 040d826a..c5f3cfc8 100644
--- a/common/alloc.c
+++ b/common/alloc.c
@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
-"$Id: alloc.c,v 1.52 2000/08/03 20:59:33 neild Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
+"$Id: alloc.c,v 1.53 2001/01/25 08:18:37 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -57,6 +57,120 @@ OMAPI_OBJECT_ALLOC (shared_network, struct shared_network,
dhcp_type_shared_network)
OMAPI_OBJECT_ALLOC (group_object, struct group_object, dhcp_type_group)
+int option_chain_head_allocate (ptr, file, line)
+ struct option_chain_head **ptr;
+ const char *file;
+ int line;
+{
+ int size;
+
+ if (!ptr) {
+ log_error ("%s(%d): null pointer", file, line);
+#if defined (POINTER_DEBUG)
+ abort ();
+#else
+ return 0;
+#endif
+ }
+ if (*ptr) {
+ log_error ("%s(%d): non-null pointer", file, line);
+#if defined (POINTER_DEBUG)
+ abort ();
+#else
+ *ptr = (struct option_chain_head *)0;
+#endif
+ }
+
+ *ptr = dmalloc (sizeof **ptr, file, line);
+ if (*ptr) {
+ memset (*ptr, 0, sizeof **ptr);
+ (*ptr) -> refcnt = 1;
+ return 1;
+ }
+ return 0;
+}
+
+int option_chain_head_reference (ptr, bp, file, line)
+ struct option_chain_head **ptr;
+ struct option_chain_head *bp;
+ const char *file;
+ int line;
+{
+ if (!ptr) {
+ log_error ("%s(%d): null pointer", file, line);
+#if defined (POINTER_DEBUG)
+ abort ();
+#else
+ return 0;
+#endif
+ }
+ if (*ptr) {
+ log_error ("%s(%d): non-null pointer", file, line);
+#if defined (POINTER_DEBUG)
+ abort ();
+#else
+ *ptr = (struct option_chain_head *)0;
+#endif
+ }
+ *ptr = bp;
+ bp -> refcnt++;
+ rc_register (file, line, ptr, bp, bp -> refcnt);
+ dmalloc_reuse (bp, file, line, 1);
+ return 1;
+}
+
+int option_chain_head_dereference (ptr, file, line)
+ struct option_chain_head **ptr;
+ const char *file;
+ int line;
+{
+ int i;
+ struct option_chain_head *option_chain_head;
+ pair car, cdr;
+
+ if (!ptr || !*ptr) {
+ log_error ("%s(%d): null pointer", file, line);
+#if defined (POINTER_DEBUG)
+ abort ();
+#else
+ return 0;
+#endif
+ }
+
+ option_chain_head = *ptr;
+ *ptr = (struct option_chain_head *)0;
+ --option_chain_head -> refcnt;
+ rc_register (file, line, ptr,
+ option_chain_head, option_chain_head -> refcnt);
+ if (option_chain_head -> refcnt > 0)
+ return 1;
+
+ if (option_chain_head -> refcnt < 0) {
+ log_error ("%s(%d): negative refcnt!", file, line);
+#if defined (DEBUG_RC_HISTORY)
+ dump_rc_history ();
+#endif
+#if defined (POINTER_DEBUG)
+ abort ();
+#else
+ return 0;
+#endif
+ }
+
+ /* If there are any options on this head, free them. */
+ for (car = option_chain_head -> first; car; car = cdr) {
+ cdr = car -> cdr;
+ if (car -> car)
+ option_cache_dereference ((struct option_cache **)
+ (&car -> car), MDL);
+ dfree (car, MDL);
+ car = cdr;
+ }
+
+ dfree (option_chain_head, file, line);
+ return 1;
+}
+
int group_allocate (ptr, file, line)
struct group **ptr;
const char *file;