2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-28 21:07:43 +00:00

[master] Fixed memory leask in omapi dereferencing

Merges in rt33990.
This commit is contained in:
Thomas Markwalder 2015-11-05 07:07:42 -05:00
parent e1634c2479
commit ce29e69574
7 changed files with 33 additions and 40 deletions

View File

@ -107,6 +107,11 @@ by Eric Young (eay@cryptsoft.com).
This is unlikely to cause significant issues in actual use. This is unlikely to cause significant issues in actual use.
[ISC-Bugs #40990] [ISC-Bugs #40990]
- Corrected a few minor memory leaks in omapi's dereferencing of
host objects. Thanks to Jiri Popelka at Red Hat for reporting
the issue and supplying the patches.
[ISC-Bugs #33990]
Changes since 4.3.3b1 Changes since 4.3.3b1
- None - None

View File

@ -3,7 +3,7 @@
OMAPI object interfaces for the DHCP server. */ OMAPI object interfaces for the DHCP server. */
/* /*
* Copyright (c) 2012,2014 Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2012,2014-2015 Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 2004-2007,2009 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2004-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999-2003 by Internet Software Consortium * Copyright (c) 1999-2003 by Internet Software Consortium
* *
@ -653,16 +653,11 @@ isc_result_t dhcp_subnet_get_value (omapi_object_t *h, omapi_object_t *id,
isc_result_t dhcp_subnet_destroy (omapi_object_t *h, const char *file, int line) isc_result_t dhcp_subnet_destroy (omapi_object_t *h, const char *file, int line)
{ {
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
struct subnet *subnet; struct subnet *subnet;
#endif
if (h -> type != dhcp_type_subnet) if (h -> type != dhcp_type_subnet)
return DHCP_R_INVALIDARG; return DHCP_R_INVALIDARG;
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
subnet = (struct subnet *)h; subnet = (struct subnet *)h;
if (subnet -> next_subnet) if (subnet -> next_subnet)
subnet_dereference (&subnet -> next_subnet, file, line); subnet_dereference (&subnet -> next_subnet, file, line);
@ -675,7 +670,6 @@ isc_result_t dhcp_subnet_destroy (omapi_object_t *h, const char *file, int line)
interface_dereference (&subnet -> interface, file, line); interface_dereference (&subnet -> interface, file, line);
if (subnet -> group) if (subnet -> group)
group_dereference (&subnet -> group, file, line); group_dereference (&subnet -> group, file, line);
#endif
return ISC_R_SUCCESS; return ISC_R_SUCCESS;
} }
@ -807,16 +801,11 @@ isc_result_t dhcp_shared_network_destroy (omapi_object_t *h,
{ {
/* In this function h should be a (struct shared_network *) */ /* In this function h should be a (struct shared_network *) */
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
struct shared_network *shared_network; struct shared_network *shared_network;
#endif
if (h -> type != dhcp_type_shared_network) if (h -> type != dhcp_type_shared_network)
return DHCP_R_INVALIDARG; return DHCP_R_INVALIDARG;
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
shared_network = (struct shared_network *)h; shared_network = (struct shared_network *)h;
if (shared_network -> next) if (shared_network -> next)
shared_network_dereference (&shared_network -> next, shared_network_dereference (&shared_network -> next,
@ -841,7 +830,6 @@ isc_result_t dhcp_shared_network_destroy (omapi_object_t *h,
&shared_network -> failover_peer, &shared_network -> failover_peer,
file, line); file, line);
#endif #endif
#endif /* DEBUG_MEMORY_LEAKAGE */
return ISC_R_SUCCESS; return ISC_R_SUCCESS;
} }

View File

@ -3467,11 +3467,8 @@ int write_leases6(void);
#if !defined(BINARY_LEASES) #if !defined(BINARY_LEASES)
void lease_insert(struct lease **, struct lease *); void lease_insert(struct lease **, struct lease *);
void lease_remove(struct lease **, struct lease *); void lease_remove(struct lease **, struct lease *);
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
void lease_remove_all(struct lease **); void lease_remove_all(struct lease **);
#endif #endif
#endif
int lease_enqueue (struct lease *); int lease_enqueue (struct lease *);
isc_result_t lease_instantiate(const void *, unsigned, void *); isc_result_t lease_instantiate(const void *, unsigned, void *);
void expire_all_pools (void); void expire_all_pools (void);

View File

@ -3,7 +3,8 @@
Routines for manipulating hash tables... */ Routines for manipulating hash tables... */
/* /*
* Copyright (c) 2009-2010,2014 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2014-2015 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-2003 by Internet Software Consortium * Copyright (c) 1995-2003 by Internet Software Consortium
* *
@ -108,7 +109,7 @@ void free_hash_table (tp, file, line)
int i; int i;
struct hash_bucket *hbc, *hbn = (struct hash_bucket *)0; struct hash_bucket *hbc, *hbn = (struct hash_bucket *)0;
for (i = 0; i < ptr -> hash_count; i++) { for (i = 0; ptr != NULL && i < ptr -> hash_count; i++) {
for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) { for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
hbn = hbc -> next; hbn = hbc -> next;
if (ptr -> dereferencer && hbc -> value) if (ptr -> dereferencer && hbc -> value)

View File

@ -402,10 +402,14 @@ int write_host (host)
++errors; ++errors;
} }
/* We're done with ip_addrs so pitch it */
data_string_forget (&ip_addrs, MDL);
errno = 0; errno = 0;
fputc (';', db_file); fputc (';', db_file);
if (errno) if (errno)
++errors; ++errors;
} }
if (host -> named_group) { if (host -> named_group) {

View File

@ -2489,10 +2489,7 @@ int write_leases ()
} }
#if !defined (BINARY_LEASES) #if !defined (BINARY_LEASES)
#if defined (DEBUG_MEMORY_LEAKAGE) || \ /* Unlink all the leases in the queue. */
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
/* Unlink all the leases in the queue. This is only used for debugging
*/
void lease_remove_all(struct lease **lq) { void lease_remove_all(struct lease **lq) {
struct lease *lp, *ln = NULL; struct lease *lp, *ln = NULL;
@ -2525,7 +2522,6 @@ void lease_remove_all(struct lease **lq) {
ln = NULL; ln = NULL;
} while (lp != NULL); } while (lp != NULL);
} }
#endif /* DEBUG_MEMORY_LEAKAGE... */
/* /*
* This routine walks through a given lease queue (lq) looking * This routine walks through a given lease queue (lq) looking
@ -3175,7 +3171,9 @@ void free_everything(void)
cancel_all_timeouts (); cancel_all_timeouts ();
relinquish_timeouts (); relinquish_timeouts ();
#if defined(DELAYED_ACK)
relinquish_ackqueue(); relinquish_ackqueue();
#endif
trace_free_all (); trace_free_all ();
group_dereference (&root_group, MDL); group_dereference (&root_group, MDL);
executable_statement_dereference (&default_classification_rules, MDL); executable_statement_dereference (&default_classification_rules, MDL);

View File

@ -455,8 +455,6 @@ isc_result_t dhcp_lease_destroy (omapi_object_t *h, const char *file, int line)
class_dereference class_dereference
(&lease->billing_class, file, line); (&lease->billing_class, file, line);
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
/* We no longer check for a next pointer as that should /* We no longer check for a next pointer as that should
* be cleared when we destroy the pool and as before we * be cleared when we destroy the pool and as before we
* should only ever be doing that on exit. * should only ever be doing that on exit.
@ -470,7 +468,6 @@ isc_result_t dhcp_lease_destroy (omapi_object_t *h, const char *file, int line)
lease_dereference (&lease->n_uid, file, line); lease_dereference (&lease->n_uid, file, line);
if (lease->next_pending) if (lease->next_pending)
lease_dereference (&lease->next_pending, file, line); lease_dereference (&lease->next_pending, file, line);
#endif
return ISC_R_SUCCESS; return ISC_R_SUCCESS;
} }
@ -1130,8 +1127,6 @@ isc_result_t dhcp_host_destroy (omapi_object_t *h, const char *file, int line)
if (h -> type != dhcp_type_host) if (h -> type != dhcp_type_host)
return DHCP_R_INVALIDARG; return DHCP_R_INVALIDARG;
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
struct host_decl *host = (struct host_decl *)h; struct host_decl *host = (struct host_decl *)h;
if (host -> n_ipaddr) if (host -> n_ipaddr)
host_dereference (&host -> n_ipaddr, file, line); host_dereference (&host -> n_ipaddr, file, line);
@ -1150,7 +1145,6 @@ isc_result_t dhcp_host_destroy (omapi_object_t *h, const char *file, int line)
omapi_object_dereference ((omapi_object_t **) omapi_object_dereference ((omapi_object_t **)
&host -> named_group, file, line); &host -> named_group, file, line);
data_string_forget (&host -> auth_key_id, file, line); data_string_forget (&host -> auth_key_id, file, line);
#endif
return ISC_R_SUCCESS; return ISC_R_SUCCESS;
} }
@ -1204,8 +1198,8 @@ isc_result_t dhcp_host_signal_handler (omapi_object_t *h,
} }
isc_result_t dhcp_host_stuff_values (omapi_object_t *c, isc_result_t dhcp_host_stuff_values (omapi_object_t *c,
omapi_object_t *id, omapi_object_t *id,
omapi_object_t *h) omapi_object_t *h)
{ {
struct host_decl *host; struct host_decl *host;
isc_result_t status; isc_result_t status;
@ -1226,16 +1220,27 @@ isc_result_t dhcp_host_stuff_values (omapi_object_t *c,
(struct option_state *)0, (struct option_state *)0,
&global_scope, &global_scope,
host -> fixed_addr, MDL)) { host -> fixed_addr, MDL)) {
status = omapi_connection_put_name (c, "ip-address"); status = omapi_connection_put_name (c, "ip-address");
if (status != ISC_R_SUCCESS) if (status != ISC_R_SUCCESS) {
data_string_forget (&ip_addrs, MDL);
return status; return status;
}
status = omapi_connection_put_uint32 (c, ip_addrs.len); status = omapi_connection_put_uint32 (c, ip_addrs.len);
if (status != ISC_R_SUCCESS) if (status != ISC_R_SUCCESS) {
data_string_forget (&ip_addrs, MDL);
return status; return status;
}
status = omapi_connection_copyin (c, status = omapi_connection_copyin (c,
ip_addrs.data, ip_addrs.len); ip_addrs.data, ip_addrs.len);
if (status != ISC_R_SUCCESS) if (status != ISC_R_SUCCESS) {
data_string_forget (&ip_addrs, MDL);
return status; return status;
}
data_string_forget (&ip_addrs, MDL);
} }
if (host -> client_identifier.len) { if (host -> client_identifier.len) {
@ -1582,16 +1587,11 @@ isc_result_t dhcp_pool_get_value (omapi_object_t *h, omapi_object_t *id,
isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line) isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line)
{ {
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
struct permit *pc, *pn; struct permit *pc, *pn;
#endif
if (h -> type != dhcp_type_pool) if (h -> type != dhcp_type_pool)
return DHCP_R_INVALIDARG; return DHCP_R_INVALIDARG;
#if defined (DEBUG_MEMORY_LEAKAGE) || \
defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
struct pool *pool = (struct pool *)h; struct pool *pool = (struct pool *)h;
if (pool -> next) if (pool -> next)
pool_dereference (&pool -> next, file, line); pool_dereference (&pool -> next, file, line);
@ -1612,6 +1612,7 @@ isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line)
dhcp_failover_state_dereference (&pool -> failover_peer, dhcp_failover_state_dereference (&pool -> failover_peer,
file, line); file, line);
#endif #endif
for (pc = pool -> permit_list; pc; pc = pn) { for (pc = pool -> permit_list; pc; pc = pn) {
pn = pc -> next; pn = pc -> next;
free_permit (pc, file, line); free_permit (pc, file, line);
@ -1623,7 +1624,6 @@ isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line)
free_permit (pc, file, line); free_permit (pc, file, line);
} }
pool -> prohibit_list = (struct permit *)0; pool -> prohibit_list = (struct permit *)0;
#endif
return ISC_R_SUCCESS; return ISC_R_SUCCESS;
} }