1995-11-29 07:40:04 +00:00
|
|
|
/* alloc.c
|
|
|
|
|
1996-02-06 20:25:56 +00:00
|
|
|
Memory allocation... */
|
1995-11-29 07:40:04 +00:00
|
|
|
|
|
|
|
/*
|
1999-03-16 05:50:46 +00:00
|
|
|
* Copyright (c) 1996-1999 Internet Software Consortium.
|
|
|
|
* Use is subject to license terms which appear in the file named
|
|
|
|
* ISC-LICENSE that should have accompanied this file when you
|
|
|
|
* received it. If a file named ISC-LICENSE did not accompany this
|
|
|
|
* file, or you are not sure the one you have is correct, you may
|
|
|
|
* obtain an applicable copy of the license at:
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* http://www.isc.org/isc-license-1.0.html.
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* This file is part of the ISC DHCP distribution. The documentation
|
|
|
|
* associated with this file is listed in the file DOCUMENTATION,
|
|
|
|
* included in the top-level directory of this release.
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* Support and other services are available for ISC products - see
|
|
|
|
* http://www.isc.org for more information.
|
1995-11-29 07:40:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char copyright[] =
|
2000-01-25 01:02:26 +00:00
|
|
|
"$Id: alloc.c,v 1.37 2000/01/25 01:02:26 mellon Exp $ Copyright (c) 1995, 1996, 1998 The Internet Software Consortium. All rights reserved.\n";
|
1995-11-29 07:40:04 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "dhcpd.h"
|
|
|
|
|
|
|
|
struct dhcp_packet *dhcp_free_list;
|
|
|
|
struct packet *packet_free_list;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL)
|
|
|
|
struct dmalloc_preamble *dmalloc_list;
|
|
|
|
unsigned long dmalloc_outstanding;
|
|
|
|
unsigned long dmalloc_longterm;
|
|
|
|
unsigned long dmalloc_generation;
|
|
|
|
unsigned long dmalloc_cutoff_generation;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (DEBUG_RC_HISTORY)
|
|
|
|
struct rc_history_entry rc_history [RC_HISTORY_MAX];
|
|
|
|
int rc_history_index;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VOIDPTR dmalloc (size, file, line)
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned size;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
unsigned char *foo = malloc (size + DMDSIZE);
|
|
|
|
int i;
|
|
|
|
VOIDPTR *bar;
|
|
|
|
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL)
|
|
|
|
struct dmalloc_preamble *dp;
|
|
|
|
#endif
|
|
|
|
if (!foo) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("No memory for %s.", name);
|
2000-01-25 01:02:26 +00:00
|
|
|
return (VOIDPTR)0;
|
|
|
|
}
|
|
|
|
bar = (VOIDPTR)(foo + DMDOFFSET);
|
|
|
|
memset (bar, 0, size);
|
|
|
|
|
|
|
|
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL)
|
|
|
|
dp = (struct dmalloc_preamble *)foo;
|
|
|
|
dp -> prev = dmalloc_list;
|
|
|
|
if (dmalloc_list)
|
|
|
|
dmalloc_list -> next = dp;
|
|
|
|
dmalloc_list = dp;
|
|
|
|
dp -> next = (struct dmalloc_preamble *)0;
|
|
|
|
dp -> size = size;
|
|
|
|
dp -> file = file;
|
|
|
|
dp -> line = line;
|
|
|
|
dp -> generation = dmalloc_generation++;
|
|
|
|
dmalloc_outstanding += size;
|
|
|
|
for (i = 0; i < DMLFSIZE; i++)
|
|
|
|
dp -> low_fence [i] =
|
|
|
|
(((unsigned long)
|
|
|
|
(&dp -> low_fence [i])) % 143) + 113;
|
|
|
|
for (i = DMDOFFSET; i < DMDSIZE; i++)
|
|
|
|
foo [i + size] =
|
|
|
|
(((unsigned long)
|
|
|
|
(&foo [i + size])) % 143) + 113;
|
|
|
|
#if defined (DEBUG_MALLOC_POOL_EXHAUSTIVELY)
|
|
|
|
/* Check _every_ entry in the pool! Very expensive. */
|
|
|
|
for (dp = dmalloc_list; dp; dp = dp -> prev) {
|
|
|
|
for (i = 0; i < DMLFSIZE; i++) {
|
|
|
|
if (dp -> low_fence [i] !=
|
|
|
|
(((unsigned long)
|
|
|
|
(&dp -> low_fence [i])) % 143) + 113)
|
|
|
|
{
|
|
|
|
log_error ("malloc fence modified: %s(%d)",
|
|
|
|
dp -> file, dp -> line);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foo = (unsigned char *)dp;
|
|
|
|
for (i = DMDOFFSET; i < DMDSIZE; i++) {
|
|
|
|
if (foo [i + dp -> size] !=
|
|
|
|
(((unsigned long)
|
|
|
|
(&foo [i + dp -> size])) % 143) + 113) {
|
|
|
|
log_error ("malloc fence modified: %s(%d)",
|
|
|
|
dp -> file, dp -> line);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return bar;
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void dfree (ptr, file, line)
|
1995-11-29 07:40:04 +00:00
|
|
|
VOIDPTR ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
1996-06-12 04:07:41 +00:00
|
|
|
if (!ptr) {
|
2000-01-25 01:02:26 +00:00
|
|
|
log_error ("dfree %s(%d): free on null pointer.", file, line);
|
1996-06-12 04:07:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-25 01:02:26 +00:00
|
|
|
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL)
|
|
|
|
{
|
|
|
|
unsigned char *bar = ptr;
|
|
|
|
struct dmalloc_preamble *dp, *cur;
|
|
|
|
int i;
|
|
|
|
bar -= DMDOFFSET;
|
|
|
|
cur = (struct dmalloc_preamble *)bar;
|
|
|
|
for (dp = dmalloc_list; dp; dp = dp -> prev)
|
|
|
|
if (dp == cur)
|
|
|
|
break;
|
|
|
|
if (!dp) {
|
|
|
|
log_error ("%s(%d): freeing unknown memory: %lx",
|
|
|
|
dp -> file, dp -> line, (unsigned long)cur);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
if (dp -> prev)
|
|
|
|
dp -> prev -> next = dp -> next;
|
|
|
|
if (dp -> next)
|
|
|
|
dp -> next -> prev = dp -> prev;
|
|
|
|
if (dp == dmalloc_list)
|
|
|
|
dmalloc_list = dp -> prev;
|
|
|
|
if (dp -> generation >= dmalloc_cutoff_generation)
|
|
|
|
dmalloc_outstanding -= dp -> size;
|
|
|
|
else
|
|
|
|
dmalloc_longterm -= dp -> size;
|
|
|
|
|
|
|
|
for (i = 0; i < DMLFSIZE; i++) {
|
|
|
|
if (dp -> low_fence [i] !=
|
|
|
|
(((unsigned long)
|
|
|
|
(&dp -> low_fence [i])) % 143) + 113)
|
|
|
|
{
|
|
|
|
log_error ("malloc fence modified: %s(%d)",
|
|
|
|
dp -> file, dp -> line);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = DMDOFFSET; i < DMDSIZE; i++) {
|
|
|
|
if (bar [i + dp -> size] !=
|
|
|
|
(((unsigned long)
|
|
|
|
(&bar [i + dp -> size])) % 143) + 113) {
|
|
|
|
log_error ("malloc fence modified: %s(%d)",
|
|
|
|
dp -> file, dp -> line);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr = bar;
|
|
|
|
}
|
|
|
|
#endif
|
1995-11-29 07:40:04 +00:00
|
|
|
free (ptr);
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL)
|
|
|
|
/* For allocation functions that keep their own free lists, we want to
|
|
|
|
account for the reuse of the memory. */
|
|
|
|
|
|
|
|
void dmalloc_reuse (foo, file, line, justref)
|
|
|
|
VOIDPTR foo;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
int justref;
|
|
|
|
{
|
|
|
|
struct dmalloc_preamble *dp;
|
|
|
|
|
|
|
|
/* Get the pointer to the dmalloc header. */
|
|
|
|
dp = foo;
|
|
|
|
dp--;
|
|
|
|
|
|
|
|
/* If we just allocated this and are now referencing it, this
|
|
|
|
function would almost be a no-op, except that it would
|
|
|
|
increment the generation count needlessly. So just return
|
|
|
|
in this case. */
|
|
|
|
if (dp -> generation == dmalloc_generation)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If this is longterm data, and we just made reference to it,
|
|
|
|
don't put it on the short-term list or change its name -
|
|
|
|
we don't need to know about this. */
|
|
|
|
if (dp -> generation < dmalloc_cutoff_generation && justref)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Take it out of the place in the allocated list where it was. */
|
|
|
|
if (dp -> prev)
|
|
|
|
dp -> prev -> next = dp -> next;
|
|
|
|
if (dp -> next)
|
|
|
|
dp -> next -> prev = dp -> prev;
|
|
|
|
if (dp == dmalloc_list)
|
|
|
|
dmalloc_list = dp -> prev;
|
|
|
|
|
|
|
|
/* Account for its removal. */
|
|
|
|
if (dp -> generation >= dmalloc_cutoff_generation)
|
|
|
|
dmalloc_outstanding -= dp -> size;
|
|
|
|
else
|
|
|
|
dmalloc_longterm -= dp -> size;
|
|
|
|
|
|
|
|
/* Now put it at the head of the list. */
|
|
|
|
dp -> prev = dmalloc_list;
|
|
|
|
if (dmalloc_list)
|
|
|
|
dmalloc_list -> next = dp;
|
|
|
|
dmalloc_list = dp;
|
|
|
|
dp -> next = (struct dmalloc_preamble *)0;
|
|
|
|
|
|
|
|
/* Change the reference location information. */
|
|
|
|
dp -> file = file;
|
|
|
|
dp -> line = line;
|
|
|
|
|
|
|
|
/* Increment the generation. */
|
|
|
|
dp -> generation = dmalloc_generation++;
|
|
|
|
|
|
|
|
/* Account for it. */
|
|
|
|
dmalloc_outstanding += dp -> size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dmalloc_dump_outstanding ()
|
|
|
|
{
|
|
|
|
static unsigned long dmalloc_cutoff_point;
|
|
|
|
struct dmalloc_preamble *dp;
|
|
|
|
unsigned char *foo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!dmalloc_cutoff_point)
|
|
|
|
dmalloc_cutoff_point = dmalloc_cutoff_generation;
|
|
|
|
for (dp = dmalloc_list; dp; dp = dp -> prev) {
|
|
|
|
if (dp -> generation <= dmalloc_cutoff_point)
|
|
|
|
break;
|
|
|
|
#if defined (DEBUG_MALLOC_POOL)
|
|
|
|
for (i = 0; i < DMLFSIZE; i++) {
|
|
|
|
if (dp -> low_fence [i] !=
|
|
|
|
(((unsigned long)
|
|
|
|
(&dp -> low_fence [i])) % 143) + 113)
|
|
|
|
{
|
|
|
|
log_error ("malloc fence modified: %s(%d)",
|
|
|
|
dp -> file, dp -> line);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foo = (unsigned char *)dp;
|
|
|
|
for (i = DMDOFFSET; i < DMDSIZE; i++) {
|
|
|
|
if (foo [i + dp -> size] !=
|
|
|
|
(((unsigned long)
|
|
|
|
(&foo [i + dp -> size])) % 143) + 113) {
|
|
|
|
log_error ("malloc fence modified: %s(%d)",
|
|
|
|
dp -> file, dp -> line);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined (DEBUG_MEMORY_LEAKAGE)
|
|
|
|
/* Don't count data that's actually on a free list
|
|
|
|
somewhere. */
|
|
|
|
if (dp -> file)
|
|
|
|
log_info (" %s(%d): %d",
|
|
|
|
dp -> file, dp -> line, dp -> size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (dmalloc_list)
|
|
|
|
dmalloc_cutoff_point = dmalloc_list -> generation;
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_MEMORY_LEAKAGE || DEBUG_MALLOC_POOL */
|
|
|
|
|
|
|
|
#if defined (DEBUG_RC_HISTORY)
|
|
|
|
void dump_rc_history ()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = rc_history_index;
|
|
|
|
do {
|
|
|
|
log_info (" referenced by %s(%d): addr = %lx refcnt = %x\n",
|
|
|
|
rc_history [i].file, rc_history [i].line,
|
|
|
|
(unsigned long)rc_history [i].addr,
|
|
|
|
rc_history [i].refcnt);
|
|
|
|
++i;
|
|
|
|
if (i == RC_HISTORY_MAX)
|
|
|
|
i = 0;
|
|
|
|
} while (i != rc_history_index && rc_history [i].file);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct dhcp_packet *new_dhcp_packet (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
|
|
|
struct dhcp_packet *rval;
|
|
|
|
rval = (struct dhcp_packet *)dmalloc (sizeof (struct dhcp_packet),
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct hash_table *new_hash_table (count, file, line)
|
1995-11-29 07:40:04 +00:00
|
|
|
int count;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
|
|
|
struct hash_table *rval = dmalloc (sizeof (struct hash_table)
|
|
|
|
- (DEFAULT_HASH_SIZE
|
|
|
|
* sizeof (struct hash_bucket *))
|
|
|
|
+ (count
|
|
|
|
* sizeof (struct hash_bucket *)),
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
rval -> hash_count = count;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct hash_bucket *new_hash_bucket (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
struct hash_bucket *rval = dmalloc (sizeof (struct hash_bucket),
|
|
|
|
file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct lease *new_leases (n, file, line)
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned n;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
struct lease *rval = dmalloc (n * sizeof (struct lease), file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct lease *new_lease (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
struct lease *rval = dmalloc (sizeof (struct lease), file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct subnet *new_subnet (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
struct subnet *rval = dmalloc (sizeof (struct subnet), file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct class *new_class (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1996-02-29 18:05:41 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
struct class *rval = dmalloc (sizeof (struct class), file, line);
|
1996-02-29 18:05:41 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct shared_network *new_shared_network (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1996-05-22 07:12:51 +00:00
|
|
|
{
|
|
|
|
struct shared_network *rval =
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct shared_network), file, line);
|
1996-05-22 07:12:51 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct group *new_group (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1996-08-27 09:31:27 +00:00
|
|
|
{
|
|
|
|
struct group *rval =
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct group), file, line);
|
1998-11-11 07:49:27 +00:00
|
|
|
if (rval)
|
|
|
|
memset (rval, 0, sizeof *rval);
|
1996-08-27 09:31:27 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct protocol *new_protocol (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-03-06 06:49:29 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
struct protocol *rval = dmalloc (sizeof (struct protocol), file, line);
|
1997-03-06 06:49:29 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct lease_state *free_lease_states;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct lease_state *new_lease_state (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-03-06 06:49:29 +00:00
|
|
|
{
|
|
|
|
struct lease_state *rval;
|
|
|
|
|
|
|
|
if (free_lease_states) {
|
|
|
|
rval = free_lease_states;
|
|
|
|
free_lease_states =
|
|
|
|
(struct lease_state *)(free_lease_states -> next);
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc_reuse (rval, file, line, 0);
|
1997-03-06 06:49:29 +00:00
|
|
|
} else {
|
2000-01-25 01:02:26 +00:00
|
|
|
rval = dmalloc (sizeof (struct lease_state), file, line);
|
1999-04-05 15:23:07 +00:00
|
|
|
if (!rval)
|
|
|
|
return rval;
|
1997-03-06 06:49:29 +00:00
|
|
|
}
|
1998-11-05 18:39:54 +00:00
|
|
|
memset (rval, 0, sizeof *rval);
|
2000-01-25 01:02:26 +00:00
|
|
|
if (!option_state_allocate (&rval -> options, file, line)) {
|
|
|
|
free_lease_state (rval, file, line);
|
1999-04-05 15:23:07 +00:00
|
|
|
return (struct lease_state *)0;
|
|
|
|
}
|
1997-03-06 06:49:29 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct domain_search_list *new_domain_search_list (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-05-09 07:56:13 +00:00
|
|
|
{
|
|
|
|
struct domain_search_list *rval =
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct domain_search_list), file, line);
|
1997-05-09 07:56:13 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct name_server *new_name_server (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-05-09 07:56:13 +00:00
|
|
|
{
|
|
|
|
struct name_server *rval =
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct name_server), file, line);
|
1997-05-09 07:56:13 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_name_server (ptr, file, line)
|
1997-05-09 07:56:13 +00:00
|
|
|
struct name_server *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-05-09 07:56:13 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1997-05-09 07:56:13 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct option *new_option (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-03-25 21:55:14 +00:00
|
|
|
{
|
|
|
|
struct option *rval =
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct option), file, line);
|
1999-03-25 21:55:14 +00:00
|
|
|
if (rval)
|
|
|
|
memset (rval, 0, sizeof *rval);
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_option (ptr, file, line)
|
1999-03-25 21:55:14 +00:00
|
|
|
struct option *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-03-25 21:55:14 +00:00
|
|
|
{
|
|
|
|
/* XXX have to put all options on heap before this is possible. */
|
|
|
|
#if 0
|
|
|
|
if (ptr -> name)
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)option -> name, file, line);
|
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1999-03-25 21:55:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct universe *new_universe (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-04-05 15:23:07 +00:00
|
|
|
{
|
|
|
|
struct universe *rval =
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct universe), file, line);
|
1999-04-05 15:23:07 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_universe (ptr, file, line)
|
1999-04-05 15:23:07 +00:00
|
|
|
struct universe *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-04-05 15:23:07 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1999-04-05 15:23:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_domain_search_list (ptr, file, line)
|
1997-05-09 07:56:13 +00:00
|
|
|
struct domain_search_list *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-05-09 07:56:13 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1997-05-09 07:56:13 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_lease_state (ptr, file, line)
|
1997-03-06 06:49:29 +00:00
|
|
|
struct lease_state *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-03-06 06:49:29 +00:00
|
|
|
{
|
1999-07-31 17:53:05 +00:00
|
|
|
if (ptr -> options)
|
2000-01-25 01:02:26 +00:00
|
|
|
option_state_dereference (&ptr -> options, file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
if (ptr -> packet)
|
2000-01-25 01:02:26 +00:00
|
|
|
packet_dereference (&ptr -> packet, file, line);
|
|
|
|
data_string_forget (&state -> parameter_request_list, file, line);
|
|
|
|
data_string_forget (&state -> filename, file, line);
|
|
|
|
data_string_forget (&state -> server_name, file, line);
|
1997-03-06 06:49:29 +00:00
|
|
|
ptr -> next = free_lease_states;
|
|
|
|
free_lease_states = ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc_reuse (free_lease_states, (char *)0, 0, 0);
|
1997-03-06 06:49:29 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_protocol (ptr, file, line)
|
1997-03-06 06:49:29 +00:00
|
|
|
struct protocol *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1997-03-06 06:49:29 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1997-03-06 06:49:29 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_group (ptr, file, line)
|
1996-08-27 09:31:27 +00:00
|
|
|
struct group *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1996-08-27 09:31:27 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1996-08-27 09:31:27 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_shared_network (ptr, file, line)
|
1996-05-22 07:12:51 +00:00
|
|
|
struct shared_network *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1996-05-22 07:12:51 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1996-05-22 07:12:51 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_class (ptr, file, line)
|
1996-02-29 18:05:41 +00:00
|
|
|
struct class *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1996-02-29 18:05:41 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1996-02-29 18:05:41 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_subnet (ptr, file, line)
|
1995-11-29 07:40:04 +00:00
|
|
|
struct subnet *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_lease (ptr, file, line)
|
1995-11-29 07:40:04 +00:00
|
|
|
struct lease *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_hash_bucket (ptr, file, line)
|
1995-11-29 07:40:04 +00:00
|
|
|
struct hash_bucket *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_hash_table (ptr, file, line)
|
1995-11-29 07:40:04 +00:00
|
|
|
struct hash_table *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_dhcp_packet (ptr, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct dhcp_packet *ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((VOIDPTR)ptr, file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct client_lease *new_client_lease (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
1998-11-05 18:39:54 +00:00
|
|
|
return (struct client_lease *)dmalloc (sizeof (struct client_lease),
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_client_lease (lease, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct client_lease *lease;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree (lease, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct pool *new_pool (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-09 02:43:42 +00:00
|
|
|
{
|
|
|
|
struct pool *pool = ((struct pool *)
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct pool), file, line));
|
1998-11-09 02:43:42 +00:00
|
|
|
if (!pool)
|
|
|
|
return pool;
|
|
|
|
memset (pool, 0, sizeof *pool);
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_pool (pool, file, line)
|
1998-11-09 02:43:42 +00:00
|
|
|
struct pool *pool;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-09 02:43:42 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree (pool, file, line);
|
1998-11-09 02:43:42 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct auth_key *new_auth_key (len, file, line)
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned len;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-02-25 23:30:43 +00:00
|
|
|
{
|
|
|
|
struct auth_key *peer;
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned size = len - 1 + sizeof (struct auth_key);
|
1999-02-25 23:30:43 +00:00
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
peer = (struct auth_key *)dmalloc (size, file, line);
|
1999-02-25 23:30:43 +00:00
|
|
|
if (!peer)
|
|
|
|
return peer;
|
|
|
|
memset (peer, 0, size);
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_auth_key (peer, file, line)
|
1999-02-25 23:30:43 +00:00
|
|
|
struct auth_key *peer;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-02-25 23:30:43 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree (peer, file, line);
|
1999-02-25 23:30:43 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
struct permit *new_permit (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-09 02:43:42 +00:00
|
|
|
{
|
|
|
|
struct permit *permit = ((struct permit *)
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc (sizeof (struct permit), file, line));
|
1998-11-09 02:43:42 +00:00
|
|
|
if (!permit)
|
|
|
|
return permit;
|
|
|
|
memset (permit, 0, sizeof *permit);
|
|
|
|
return permit;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_permit (permit, file, line)
|
1998-11-09 02:43:42 +00:00
|
|
|
struct permit *permit;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-09 02:43:42 +00:00
|
|
|
{
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree (permit, file, line);
|
1998-11-09 02:43:42 +00:00
|
|
|
}
|
|
|
|
|
1998-11-05 18:39:54 +00:00
|
|
|
pair free_pairs;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
pair new_pair (file, line)
|
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
pair foo;
|
|
|
|
|
|
|
|
if (free_pairs) {
|
|
|
|
foo = free_pairs;
|
|
|
|
free_pairs = foo -> cdr;
|
|
|
|
memset (foo, 0, sizeof *foo);
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc_reuse (foo, file, line, 0);
|
1998-11-05 18:39:54 +00:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
foo = dmalloc (sizeof *foo, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!foo)
|
|
|
|
return foo;
|
|
|
|
memset (foo, 0, sizeof *foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_pair (foo, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
pair foo;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
foo -> cdr = free_pairs;
|
|
|
|
free_pairs = foo;
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc_reuse (free_expressions, (char *)0, 0, 0);
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct expression *free_expressions;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int expression_allocate (cptr, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct expression **cptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
struct expression *rval;
|
|
|
|
|
|
|
|
if (free_expressions) {
|
|
|
|
rval = free_expressions;
|
|
|
|
free_expressions = rval -> data.not;
|
|
|
|
} else {
|
2000-01-25 01:02:26 +00:00
|
|
|
rval = dmalloc (sizeof (struct expression), file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!rval)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memset (rval, 0, sizeof *rval);
|
2000-01-25 01:02:26 +00:00
|
|
|
return expression_reference (cptr, rval, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int expression_reference (ptr, src, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct expression **ptr;
|
|
|
|
struct expression *src;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
2000-01-25 01:02:26 +00:00
|
|
|
log_error ("Null pointer in expression_reference: %s",
|
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
if (*ptr) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("Non-null pointer in expression_reference (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
1999-05-27 12:38:05 +00:00
|
|
|
*ptr = (struct expression *)0;
|
1999-05-07 17:36:36 +00:00
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
*ptr = src;
|
|
|
|
src -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, src, src -> refcnt);
|
|
|
|
dmalloc_reuse (src, file, line, 1);
|
1998-11-05 18:39:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
void free_expression (expr, file, line)
|
|
|
|
struct expression *expr;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
{
|
|
|
|
expr -> data.not = free_expressions;
|
|
|
|
free_expressions = expr;
|
|
|
|
dmalloc_reuse (free_expressions, (char *)0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-05 18:39:54 +00:00
|
|
|
struct option_cache *free_option_caches;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int option_cache_allocate (cptr, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct option_cache **cptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
struct option_cache *rval;
|
|
|
|
|
|
|
|
if (free_option_caches) {
|
|
|
|
rval = free_option_caches;
|
|
|
|
free_option_caches =
|
|
|
|
(struct option_cache *)(rval -> expression);
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc_reuse (rval, file, line, 0);
|
1998-11-05 18:39:54 +00:00
|
|
|
} else {
|
2000-01-25 01:02:26 +00:00
|
|
|
rval = dmalloc (sizeof (struct option_cache), file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!rval)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memset (rval, 0, sizeof *rval);
|
2000-01-25 01:02:26 +00:00
|
|
|
return option_cache_reference (cptr, rval, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int option_cache_reference (ptr, src, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct option_cache **ptr;
|
|
|
|
struct option_cache *src;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
2000-01-25 01:02:26 +00:00
|
|
|
log_error ("Null pointer in option_cache_reference: %s",
|
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
if (*ptr) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("Non-null pointer in option_cache_reference (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
1999-05-27 12:38:05 +00:00
|
|
|
*ptr = (struct option_cache *)0;
|
1999-05-07 17:36:36 +00:00
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
*ptr = src;
|
|
|
|
src -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, src, src -> refcnt);
|
|
|
|
dmalloc_reuse (src, file, line, 1);
|
1998-11-05 18:39:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int buffer_allocate (ptr, len, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct buffer **ptr;
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned len;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
struct buffer *bp;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
bp = dmalloc (len + sizeof *bp, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!bp)
|
|
|
|
return 0;
|
|
|
|
memset (bp, 0, sizeof *bp);
|
|
|
|
bp -> refcnt = 0;
|
2000-01-25 01:02:26 +00:00
|
|
|
return buffer_reference (ptr, bp, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int buffer_reference (ptr, bp, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct buffer **ptr;
|
|
|
|
struct buffer *bp;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
1999-04-05 15:23:07 +00:00
|
|
|
log_error ("Null pointer passed to buffer_reference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
if (*ptr) {
|
2000-01-25 01:02:26 +00:00
|
|
|
log_error ("Non-null pointer in buffer_reference (%s)",
|
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
1999-05-27 12:38:05 +00:00
|
|
|
*ptr = (struct buffer *)0;
|
1999-05-07 17:36:36 +00:00
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
*ptr = bp;
|
|
|
|
bp -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, bp, bp -> refcnt);
|
|
|
|
dmalloc_reuse (bp, file, line, 1);
|
1998-11-05 18:39:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int buffer_dereference (ptr, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct buffer **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
struct buffer *bp;
|
|
|
|
|
1999-05-27 12:38:05 +00:00
|
|
|
if (!ptr) {
|
1999-04-05 15:23:07 +00:00
|
|
|
log_error ("Null pointer passed to buffer_dereference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
1999-05-27 12:38:05 +00:00
|
|
|
if (!*ptr) {
|
2000-01-25 01:02:26 +00:00
|
|
|
log_error ("Null pointer in buffer_dereference: %s",
|
|
|
|
file, line);
|
1999-05-27 12:38:05 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1998-11-05 18:39:54 +00:00
|
|
|
(*ptr) -> refcnt--;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (name, line, *ptr, (*ptr) -> refcnt);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!(*ptr) -> refcnt)
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((*ptr), file, line);
|
|
|
|
if ((*ptr) -> refcnt < 0) {
|
|
|
|
log_error ("buffer_dereference: negative refcnt!");
|
|
|
|
#if defined (DEBUG_RC_HISTORY)
|
|
|
|
dump_rc_history ();
|
|
|
|
#endif
|
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
1998-11-05 18:39:54 +00:00
|
|
|
*ptr = (struct buffer *)0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int dns_host_entry_allocate (ptr, hostname, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct dns_host_entry **ptr;
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *hostname;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
struct dns_host_entry *bp;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
bp = dmalloc (strlen (hostname) + sizeof *bp, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!bp)
|
|
|
|
return 0;
|
|
|
|
memset (bp, 0, sizeof *bp);
|
|
|
|
bp -> refcnt = 0;
|
1998-11-06 01:06:44 +00:00
|
|
|
strcpy (bp -> hostname, hostname);
|
2000-01-25 01:02:26 +00:00
|
|
|
return dns_host_entry_reference (ptr, bp, file, line);
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int dns_host_entry_reference (ptr, bp, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct dns_host_entry **ptr;
|
|
|
|
struct dns_host_entry *bp;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
1999-04-05 15:23:07 +00:00
|
|
|
log_error ("Null pointer in dns_host_entry_reference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
if (*ptr) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("Non-null pointer in dns_host_entry_reference (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
1999-05-27 12:38:05 +00:00
|
|
|
*ptr = (struct dns_host_entry *)0;
|
1999-05-07 17:36:36 +00:00
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
*ptr = bp;
|
|
|
|
bp -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, bp, bp -> refcnt);
|
|
|
|
dmalloc_reuse (bp, file, line, 1);
|
1998-11-05 18:39:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int dns_host_entry_dereference (ptr, file, line)
|
1998-11-05 18:39:54 +00:00
|
|
|
struct dns_host_entry **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1998-11-05 18:39:54 +00:00
|
|
|
{
|
|
|
|
struct dns_host_entry *bp;
|
|
|
|
|
|
|
|
if (!ptr || !*ptr) {
|
1999-04-05 15:23:07 +00:00
|
|
|
log_error ("Null pointer in dns_host_entry_dereference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1998-11-05 18:39:54 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1998-11-05 18:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(*ptr) -> refcnt--;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, bp, bp -> refcnt);
|
1998-11-05 18:39:54 +00:00
|
|
|
if (!(*ptr) -> refcnt)
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree ((*ptr), file, line);
|
|
|
|
if ((*ptr) -> refcnt < 0) {
|
|
|
|
log_error ("dns_host_entry_dereference: negative refcnt!");
|
|
|
|
#if defined (DEBUG_RC_HISTORY)
|
|
|
|
dump_rc_history ();
|
|
|
|
#endif
|
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
1998-11-05 18:39:54 +00:00
|
|
|
*ptr = (struct dns_host_entry *)0;
|
|
|
|
return 1;
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
1999-04-05 15:23:07 +00:00
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int option_state_allocate (ptr, file, line)
|
1999-04-05 15:23:07 +00:00
|
|
|
struct option_state **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-04-05 15:23:07 +00:00
|
|
|
{
|
1999-10-07 06:36:35 +00:00
|
|
|
unsigned size;
|
1999-04-05 15:23:07 +00:00
|
|
|
|
|
|
|
if (!ptr) {
|
|
|
|
log_error ("Null pointer passed to option_state_allocate: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1999-04-05 15:23:07 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1999-04-05 15:23:07 +00:00
|
|
|
}
|
|
|
|
if (*ptr) {
|
|
|
|
log_error ("Non-null pointer in option_state_allocate (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1999-04-05 15:23:07 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
1999-05-27 12:38:05 +00:00
|
|
|
*ptr = (struct option_state *)0;
|
1999-05-07 17:36:36 +00:00
|
|
|
#endif
|
1999-04-05 15:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof **ptr + (universe_count - 1) * sizeof (VOIDPTR);
|
2000-01-25 01:02:26 +00:00
|
|
|
*ptr = dmalloc (size, file, line);
|
1999-04-05 15:23:07 +00:00
|
|
|
if (*ptr) {
|
|
|
|
memset (*ptr, 0, size);
|
|
|
|
(*ptr) -> universe_count = universe_count;
|
1999-04-05 19:02:17 +00:00
|
|
|
(*ptr) -> refcnt = 1;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, *ptr, (*ptr) -> refcnt);
|
1999-04-05 15:23:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int option_state_reference (ptr, bp, file, line)
|
1999-04-05 19:02:17 +00:00
|
|
|
struct option_state **ptr;
|
|
|
|
struct option_state *bp;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-04-05 19:02:17 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
|
|
|
log_error ("Null pointer in option_state_reference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1999-04-05 19:02:17 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1999-04-05 19:02:17 +00:00
|
|
|
}
|
|
|
|
if (*ptr) {
|
|
|
|
log_error ("Non-null pointer in option_state_reference (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1999-04-05 19:02:17 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
1999-05-27 12:38:05 +00:00
|
|
|
*ptr = (struct option_state *)0;
|
1999-05-07 17:36:36 +00:00
|
|
|
#endif
|
1999-04-05 19:02:17 +00:00
|
|
|
}
|
|
|
|
*ptr = bp;
|
|
|
|
bp -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, bp, bp -> refcnt);
|
|
|
|
dmalloc_reuse (bp, file, line, 1);
|
1999-04-05 19:02:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int option_state_dereference (ptr, file, line)
|
1999-04-05 15:23:07 +00:00
|
|
|
struct option_state **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-04-05 15:23:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
1999-04-05 19:02:17 +00:00
|
|
|
struct option_state *options;
|
1999-04-05 15:23:07 +00:00
|
|
|
|
|
|
|
if (!ptr || !*ptr) {
|
|
|
|
log_error ("Null pointer in option_state_dereference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-05-07 17:36:36 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
1999-04-05 15:23:07 +00:00
|
|
|
abort ();
|
1999-05-07 17:36:36 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
1999-04-05 15:23:07 +00:00
|
|
|
}
|
|
|
|
|
1999-04-05 19:02:17 +00:00
|
|
|
options = *ptr;
|
|
|
|
*ptr = (struct option_state *)0;
|
|
|
|
--options -> refcnt;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, options, options -> refcnt);
|
|
|
|
if (options -> refcnt > 0)
|
1999-04-05 19:02:17 +00:00
|
|
|
return 1;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
if (options -> refcnt < 0) {
|
|
|
|
log_error ("option_state_dereference: negative refcnt!");
|
|
|
|
#if defined (DEBUG_RC_HISTORY)
|
|
|
|
dump_rc_history ();
|
|
|
|
#endif
|
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-04-05 15:23:07 +00:00
|
|
|
/* Loop through the per-universe state. */
|
1999-04-05 19:02:17 +00:00
|
|
|
for (i = 0; i < options -> universe_count; i++)
|
|
|
|
if (options -> universes [i] &&
|
1999-04-05 15:23:07 +00:00
|
|
|
universes [i] -> option_state_dereference)
|
|
|
|
((*(universes [i] -> option_state_dereference))
|
1999-04-05 19:02:17 +00:00
|
|
|
(universes [i], options));
|
1999-04-05 15:23:07 +00:00
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
dfree (options, file, line);
|
1999-04-05 15:23:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1999-07-16 21:34:14 +00:00
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int executable_statement_allocate (ptr, file, line)
|
1999-07-16 21:34:14 +00:00
|
|
|
struct executable_statement **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-07-16 21:34:14 +00:00
|
|
|
{
|
|
|
|
struct executable_statement *bp;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
bp = dmalloc (sizeof *bp, file, line);
|
1999-07-16 21:34:14 +00:00
|
|
|
if (!bp)
|
|
|
|
return 0;
|
|
|
|
memset (bp, 0, sizeof *bp);
|
2000-01-25 01:02:26 +00:00
|
|
|
return executable_statement_reference (ptr, bp, file, line);
|
1999-07-16 21:34:14 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int executable_statement_reference (ptr, bp, file, line)
|
1999-07-16 21:34:14 +00:00
|
|
|
struct executable_statement **ptr;
|
|
|
|
struct executable_statement *bp;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-07-16 21:34:14 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
|
|
|
log_error ("Null ptr in executable_statement_reference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-16 21:34:14 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (*ptr) {
|
|
|
|
log_error ("Nonnull ptr in executable_statement_reference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-16 21:34:14 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
*ptr = (struct executable_statement *)0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
*ptr = bp;
|
|
|
|
bp -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, bp, bp -> refcnt);
|
|
|
|
dmalloc_reuse (bp, file, line, 1);
|
1999-07-16 21:34:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1999-07-31 17:53:05 +00:00
|
|
|
|
|
|
|
static struct packet *free_packets;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int packet_allocate (ptr, file, line)
|
1999-07-31 17:53:05 +00:00
|
|
|
struct packet **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-07-31 17:53:05 +00:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (!ptr) {
|
|
|
|
log_error ("Null pointer passed to packet_allocate: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (*ptr) {
|
|
|
|
log_error ("Non-null pointer in packet_allocate (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
*ptr = (struct packet *)0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
*ptr = dmalloc (sizeof **ptr, file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
if (*ptr) {
|
|
|
|
memset (*ptr, 0, sizeof **ptr);
|
|
|
|
(*ptr) -> refcnt = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int packet_reference (ptr, bp, file, line)
|
1999-07-31 17:53:05 +00:00
|
|
|
struct packet **ptr;
|
|
|
|
struct packet *bp;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-07-31 17:53:05 +00:00
|
|
|
{
|
|
|
|
if (!ptr) {
|
|
|
|
log_error ("Null pointer in packet_reference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (*ptr) {
|
|
|
|
log_error ("Non-null pointer in packet_reference (%s)",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
*ptr = (struct packet *)0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
*ptr = bp;
|
|
|
|
bp -> refcnt++;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, bp, bp -> refcnt);
|
|
|
|
dmalloc_reuse (bp, file, line, 1);
|
1999-07-31 17:53:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
int packet_dereference (ptr, file, line)
|
1999-07-31 17:53:05 +00:00
|
|
|
struct packet **ptr;
|
2000-01-25 01:02:26 +00:00
|
|
|
const char *file;
|
|
|
|
int line;
|
1999-07-31 17:53:05 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct packet *packet;
|
|
|
|
|
|
|
|
if (!ptr || !*ptr) {
|
|
|
|
log_error ("Null pointer in packet_dereference: %s",
|
2000-01-25 01:02:26 +00:00
|
|
|
file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
packet = *ptr;
|
|
|
|
*ptr = (struct packet *)0;
|
|
|
|
--packet -> refcnt;
|
2000-01-25 01:02:26 +00:00
|
|
|
rc_register (file, line, packet, packet -> refcnt);
|
|
|
|
if (packet -> refcnt > 0)
|
1999-07-31 17:53:05 +00:00
|
|
|
return 1;
|
|
|
|
|
2000-01-25 01:02:26 +00:00
|
|
|
if (packet -> refcnt < 0) {
|
|
|
|
log_error ("option_state_dereference: negative refcnt!");
|
|
|
|
#if defined (DEBUG_RC_HISTORY)
|
|
|
|
dump_rc_history ();
|
|
|
|
#endif
|
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-07-31 17:53:05 +00:00
|
|
|
if (packet -> options)
|
2000-01-25 01:02:26 +00:00
|
|
|
option_state_dereference (&packet -> options, file, line);
|
1999-07-31 17:53:05 +00:00
|
|
|
packet -> raw = (struct dhcp_packet *)free_packets;
|
|
|
|
free_packets = packet;
|
2000-01-25 01:02:26 +00:00
|
|
|
dmalloc_reuse (free_packets, (char *)0, 0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int binding_scope_allocate (ptr, file, line)
|
|
|
|
struct binding_scope **ptr;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
{
|
|
|
|
struct binding_scope *bp;
|
|
|
|
|
|
|
|
if (!ptr) {
|
|
|
|
log_error ("Null pointer in binding_scope_allocate: %s",
|
|
|
|
file, line);
|
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ptr) {
|
|
|
|
log_error ("Non-null pointer in binding_scope_allocate: %s",
|
|
|
|
file, line);
|
|
|
|
#if defined (POINTER_DEBUG)
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bp = dmalloc (sizeof *bp, file, line);
|
|
|
|
if (!bp)
|
|
|
|
return 0;
|
|
|
|
memset (bp, 0, sizeof *bp);
|
|
|
|
*ptr = bp;
|
1999-07-31 17:53:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2000-01-25 01:02:26 +00:00
|
|
|
|
|
|
|
/* Make a copy of the data in data_string, upping the buffer reference
|
|
|
|
count if there's a buffer. */
|
|
|
|
|
|
|
|
void data_string_copy (dest, src, file, line)
|
|
|
|
struct data_string *dest;
|
|
|
|
struct data_string *src;
|
|
|
|
const char *name;
|
|
|
|
int line;
|
|
|
|
{
|
|
|
|
if (src -> buffer)
|
|
|
|
buffer_reference (&dest -> buffer, src -> buffer, file, line);
|
|
|
|
dest -> data = src -> data;
|
|
|
|
dest -> terminated = src -> terminated;
|
|
|
|
dest -> len = src -> len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the reference count to a data string's buffer (if any) and
|
|
|
|
zero out the other information, yielding the null data string. */
|
|
|
|
|
|
|
|
void data_string_forget (data, name)
|
|
|
|
struct data_string *data;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
{
|
|
|
|
if (data -> buffer)
|
|
|
|
buffer_dereference (&data -> buffer, file, line);
|
|
|
|
memset (data, 0, sizeof *data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a copy of the data in data_string, upping the buffer reference
|
|
|
|
count if there's a buffer. */
|
|
|
|
|
|
|
|
void data_string_truncate (dp, len)
|
|
|
|
struct data_string *dp;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
if (len < dp -> len) {
|
|
|
|
dp -> terminated = 0;
|
|
|
|
dp -> len = len;
|
|
|
|
}
|
|
|
|
}
|