mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-01 14:55:30 +00:00
Merge changes between 3.0rc7 and 3.0rc8pl2.
This commit is contained in:
113
server/salloc.c
113
server/salloc.c
@@ -3,7 +3,7 @@
|
||||
Memory allocation for the DHCP server... */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996-2000 Internet Software Consortium.
|
||||
* Copyright (c) 1996-2001 Internet Software Consortium.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,21 +43,112 @@
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"$Id: salloc.c,v 1.3 2001/06/22 16:47:20 brister Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
|
||||
"$Id: salloc.c,v 1.4 2001/06/27 00:31:16 mellon Exp $ Copyright (c) 1996-2001 The Internet Software Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include <omapip/omapip_p.h>
|
||||
|
||||
#if defined (COMPACT_LEASES)
|
||||
struct lease *free_leases;
|
||||
|
||||
# if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
|
||||
struct lease *lease_hunks;
|
||||
|
||||
void relinquish_lease_hunks ()
|
||||
{
|
||||
struct lease *c, *n, **p, *f;
|
||||
int i;
|
||||
|
||||
/* Account for all the leases on the free list. */
|
||||
for (n = lease_hunks; n; n = n -> next) {
|
||||
for (i = 1; i < n -> starts + 1; i++) {
|
||||
p = &free_leases;
|
||||
for (c = free_leases; c; c = c -> next) {
|
||||
if (c == &n [i]) {
|
||||
*p = c -> next;
|
||||
n -> ends++;
|
||||
break;
|
||||
}
|
||||
p = &c -> next;
|
||||
}
|
||||
if (!c) {
|
||||
log_info ("lease %s refcnt %d",
|
||||
piaddr (n [i].ip_addr), n [i].refcnt);
|
||||
dump_rc_history (&n [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (c = lease_hunks; c; c = n) {
|
||||
n = c -> next;
|
||||
if (c -> ends != c -> starts) {
|
||||
log_info ("lease hunk %lx leases %ld free %ld",
|
||||
(unsigned long)c, (unsigned long)c -> starts,
|
||||
(unsigned long)c -> ends);
|
||||
}
|
||||
dfree (c, MDL);
|
||||
}
|
||||
|
||||
/* Free all the rogue leases. */
|
||||
for (c = free_leases; c; c = n) {
|
||||
n = c -> next;
|
||||
dfree (c, MDL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct lease *new_leases (n, file, line)
|
||||
unsigned n;
|
||||
const char *file;
|
||||
int line;
|
||||
{
|
||||
struct lease *rval = dmalloc (n * sizeof (struct lease), file, line);
|
||||
struct lease *rval;
|
||||
#if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
|
||||
rval = dmalloc ((n + 1) * sizeof (struct lease), file, line);
|
||||
memset (rval, 0, sizeof (struct lease));
|
||||
rval -> starts = n;
|
||||
rval -> next = lease_hunks;
|
||||
lease_hunks = rval;
|
||||
rval++;
|
||||
#else
|
||||
rval = dmalloc (n * sizeof (struct lease), file, line);
|
||||
#endif
|
||||
return rval;
|
||||
}
|
||||
|
||||
/* If we are allocating leases in aggregations, there's really no way
|
||||
to free one, although perhaps we can maintain a free list. */
|
||||
|
||||
isc_result_t dhcp_lease_free (omapi_object_t *lo,
|
||||
const char *file, int line)
|
||||
{
|
||||
struct lease *lease;
|
||||
if (lo -> type != dhcp_type_lease)
|
||||
return ISC_R_INVALIDARG;
|
||||
lease = (struct lease *)lo;
|
||||
memset (lease, 0, sizeof (struct lease));
|
||||
lease -> next = free_leases;
|
||||
free_leases = lease;
|
||||
return ISC_R_SUCCESS;
|
||||
}
|
||||
|
||||
isc_result_t dhcp_lease_get (omapi_object_t **lp,
|
||||
const char *file, int line)
|
||||
{
|
||||
struct lease **lease = (struct lease **)lp;
|
||||
struct lease *lt;
|
||||
|
||||
if (free_leases) {
|
||||
lt = free_leases;
|
||||
free_leases = lt -> next;
|
||||
*lease = lt;
|
||||
return ISC_R_SUCCESS;
|
||||
}
|
||||
return ISC_R_NOMEMORY;
|
||||
}
|
||||
#endif /* COMPACT_LEASES */
|
||||
|
||||
OMAPI_OBJECT_ALLOC (lease, struct lease, dhcp_type_lease)
|
||||
OMAPI_OBJECT_ALLOC (class, struct class, dhcp_type_class)
|
||||
OMAPI_OBJECT_ALLOC (subclass, struct class, dhcp_type_subclass)
|
||||
@@ -140,6 +231,20 @@ void free_lease_state (ptr, file, line)
|
||||
dmalloc_reuse (free_lease_states, (char *)0, 0, 0);
|
||||
}
|
||||
|
||||
#if defined (DEBUG_MEMORY_LEAKAGE) || \
|
||||
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
|
||||
void relinquish_free_lease_states ()
|
||||
{
|
||||
struct lease_state *cs, *ns;
|
||||
|
||||
for (cs = free_lease_states; cs; cs = ns) {
|
||||
ns = cs -> next;
|
||||
dfree (cs, MDL);
|
||||
}
|
||||
free_lease_states = (struct lease_state *)0;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct permit *new_permit (file, line)
|
||||
const char *file;
|
||||
int line;
|
||||
@@ -157,5 +262,7 @@ void free_permit (permit, file, line)
|
||||
const char *file;
|
||||
int line;
|
||||
{
|
||||
if (permit -> type == permit_class)
|
||||
class_dereference (&permit -> class, MDL);
|
||||
dfree (permit, file, line);
|
||||
}
|
||||
|
Reference in New Issue
Block a user