Commit 292031c9 authored by James Brister's avatar James Brister
Browse files

- Removed config *_delete functions on structures that use reference

  counting and replaced with *_detach.
- Changed config *_attach functions to return the new attached value through
  the paramater list rather than as a return value.
- Changed config *_delete functions to no longer allow deletion of a null
  pointer
- Changed calls to the config *_delete functions to make sure no null
  pointers were passed in.
- Changed use of the config *_attach function to match new signature.
parent 715799a3
......@@ -74,11 +74,9 @@ dns_c_acltable_delete(isc_log_t *lctx,
isc_mem_t *mem;
REQUIRE(table != NULL);
REQUIRE(*table != NULL);
acltable = *table;
if (acltable == NULL) {
return (ISC_R_SUCCESS);
}
REQUIRE(DNS_CONFACLTABLE_VALID(acltable));
......@@ -291,7 +289,7 @@ dns_c_acl_setipml(isc_log_t *lctx, dns_c_acl_t *acl,
REQUIRE(ipml != NULL);
if (acl->ipml != NULL) {
dns_c_ipmatchlist_delete(lctx, &acl->ipml);
dns_c_ipmatchlist_detach(lctx, &acl->ipml);
}
if (deepcopy) {
......@@ -405,11 +403,9 @@ acl_delete(isc_log_t *lctx, dns_c_acl_t **aclptr)
isc_mem_t *mem;
REQUIRE(aclptr != NULL);
REQUIRE(*aclptr != NULL);
acl = *aclptr;
if (acl == NULL) {
return (ISC_R_SUCCESS);
}
REQUIRE(DNS_CONFACL_VALID(acl));
......@@ -418,8 +414,12 @@ acl_delete(isc_log_t *lctx, dns_c_acl_t **aclptr)
acl->mytable = NULL;
isc_mem_free(mem, acl->name);
res = dns_c_ipmatchlist_delete(lctx, &acl->ipml);
if (acl->ipml != NULL)
res = dns_c_ipmatchlist_detach(lctx, &acl->ipml);
else
res = ISC_R_SUCCESS;
acl->magic = 0;
isc_mem_put(mem, acl, sizeof *acl);
......
......@@ -100,11 +100,9 @@ dns_c_ctrllist_delete(isc_log_t *lctx,
dns_c_ctrllist_t *clist;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
clist = *list;
if (clist == NULL) {
return (ISC_R_SUCCESS);
}
REQUIRE(DNS_CONFCTLLIST_VALID(clist));
......@@ -209,11 +207,9 @@ dns_c_ctrl_delete(isc_log_t *lctx,
dns_c_ctrl_t *ctrl;
REQUIRE(control != NULL);
REQUIRE(*control != NULL);
ctrl = *control;
if (ctrl == NULL) {
return (ISC_R_SUCCESS);
}
REQUIRE(DNS_CONFCTL_VALID(ctrl));
......@@ -221,8 +217,11 @@ dns_c_ctrl_delete(isc_log_t *lctx,
switch (ctrl->control_type) {
case dns_c_inet_control:
res = dns_c_ipmatchlist_delete(lctx,
&ctrl->u.inet_v.matchlist);
if (ctrl->u.inet_v.matchlist != NULL)
res = dns_c_ipmatchlist_detach(lctx,
&ctrl->u.inet_v.matchlist);
else
res = ISC_R_SUCCESS;
break;
case dns_c_unix_control:
......
......@@ -195,15 +195,32 @@ dns_c_ctx_delete(isc_log_t *lctx,
REQUIRE(c->mem != NULL);
dns_c_ctx_optionsdelete(lctx, &c->options);
dns_c_ctrllist_delete(lctx, &c->controls);
dns_c_srvlist_delete(lctx, &c->servers);
dns_c_acltable_delete(lctx, &c->acls);
dns_c_kdeflist_delete(lctx, &c->keydefs);
dns_c_zonelist_delete(lctx, &c->zlist);
dns_c_tkeylist_delete(lctx, &c->trusted_keys);
dns_c_logginglist_delete(lctx, &c->logging);
dns_c_viewtable_delete(lctx, &c->views);
if (c->options != NULL)
dns_c_ctx_optionsdelete(lctx, &c->options);
if (c->controls != NULL)
dns_c_ctrllist_delete(lctx, &c->controls);
if (c->servers != NULL)
dns_c_srvlist_delete(lctx, &c->servers);
if (c->acls != NULL)
dns_c_acltable_delete(lctx, &c->acls);
if (c->keydefs != NULL)
dns_c_kdeflist_delete(lctx, &c->keydefs);
if (c->zlist != NULL)
dns_c_zonelist_delete(lctx, &c->zlist);
if (c->trusted_keys != NULL)
dns_c_tkeylist_delete(lctx, &c->trusted_keys);
if (c->logging != NULL)
dns_c_logginglist_delete(lctx, &c->logging);
if (c->views != NULL)
dns_c_viewtable_delete(lctx, &c->views);
isc_mem_put(c->mem, c, sizeof *c);
*cfg = NULL;
......@@ -3051,7 +3068,7 @@ dns_c_ctx_optionsdelete(isc_log_t *lctx,
dns_c_options_t **opts)
{
dns_c_options_t *options;
isc_result_t r;
isc_result_t r, result;
REQUIRE(opts != NULL);
......@@ -3098,39 +3115,68 @@ dns_c_ctx_optionsdelete(isc_log_t *lctx,
isc_mem_free(options->mem, options->tkeydhkeycp);
}
r = dns_c_ipmatchlist_delete(lctx, &options->queryacl);
if (r != ISC_R_SUCCESS) return (r);
result = ISC_R_SUCCESS;
r = dns_c_ipmatchlist_delete(lctx, &options->transferacl);
if (r != ISC_R_SUCCESS) return (r);
if (options->queryacl != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->queryacl);
if (r != ISC_R_SUCCESS)
result = r;
}
r = dns_c_ipmatchlist_delete(lctx, &options->recursionacl);
if (r != ISC_R_SUCCESS) return (r);
if (options->transferacl != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->transferacl);
if (r != ISC_R_SUCCESS)
result = r;
}
r = dns_c_ipmatchlist_delete(lctx, &options->blackhole);
if (r != ISC_R_SUCCESS) return (r);
if (options->recursionacl != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->recursionacl);
if (r != ISC_R_SUCCESS)
result = r;
}
r = dns_c_ipmatchlist_delete(lctx, &options->topology);
if (r != ISC_R_SUCCESS) return (r);
if (options->blackhole != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->blackhole);
if (r != ISC_R_SUCCESS)
result = r;
}
if (options->topology != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->topology);
if (r != ISC_R_SUCCESS)
result = r;
}
if (options->sortlist != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->sortlist);
if (r != ISC_R_SUCCESS)
result = r;
}
if (options->listens != NULL) {
r = dns_c_lstnlist_delete(lctx, &options->listens);
if (r != ISC_R_SUCCESS)
result = r;
}
if (options->ordering != NULL) {
r = dns_c_rrsolist_delete(lctx, &options->ordering);
if (r != ISC_R_SUCCESS)
result = r;
}
if (options->forwarders != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &options->forwarders);
if (r != ISC_R_SUCCESS)
result = r;
}
r = dns_c_ipmatchlist_delete(lctx, &options->sortlist);
if (r != ISC_R_SUCCESS) return (r);
r = dns_c_lstnlist_delete(lctx, &options->listens);
if (r != ISC_R_SUCCESS) return (r);
r = dns_c_rrsolist_delete(lctx, &options->ordering);
if (r != ISC_R_SUCCESS) return (r);
r = dns_c_ipmatchlist_delete(lctx, &options->forwarders);
if (r != ISC_R_SUCCESS) return (r);
*opts = NULL;
options->magic = 0;
isc_mem_put(options->mem, options, sizeof *options);
return (ISC_R_SUCCESS);
return (result);
}
......@@ -3493,7 +3539,7 @@ cfg_set_iplist(isc_log_t *lctx,
}
} else {
if (*fieldaddr != NULL) {
res = dns_c_ipmatchlist_delete(lctx, fieldaddr);
res = dns_c_ipmatchlist_detach(lctx, fieldaddr);
if (res != ISC_R_SUCCESS) {
return (res);
}
......
......@@ -99,11 +99,8 @@ dns_c_ipmatchelement_delete(isc_log_t *lctx,
REQUIRE(mem != NULL);
REQUIRE(ipme != NULL);
REQUIRE(*ipme != NULL);
if (*ipme == NULL) {
return (ISC_R_SUCCESS);
}
elem = *ipme;
REQUIRE(DNS_IPMELEM_VALID(elem));
......@@ -118,7 +115,9 @@ dns_c_ipmatchelement_delete(isc_log_t *lctx,
case dns_c_ipmatch_indirect:
INSIST(elem->u.indirect.list != NULL);
dns_c_ipmatchlist_delete(lctx, &elem->u.indirect.list);
if (elem->u.indirect.list != NULL)
dns_c_ipmatchlist_detach(lctx, &elem->u.indirect.list);
if (elem->u.indirect.refname.base != NULL) {
isc_mem_put(mem, elem->u.indirect.refname.base,
elem->u.indirect.refname.length);
......@@ -330,7 +329,7 @@ dns_c_ipmatchindirect_new(isc_log_t *lctx,
strcpy(ime->u.indirect.refname.base, name);
}
} else {
dns_c_ipmatchlist_delete(lctx, &iml_copy);
dns_c_ipmatchlist_detach(lctx, &iml_copy);
}
*result = ime;
......@@ -481,7 +480,7 @@ dns_c_ipmatchlist_new(isc_log_t *lctx,
isc_result_t
dns_c_ipmatchlist_delete(isc_log_t *lctx,
dns_c_ipmatchlist_detach(isc_log_t *lctx,
dns_c_ipmatchlist_t **ml)
{
dns_c_ipmatchelement_t *ime;
......@@ -490,11 +489,9 @@ dns_c_ipmatchlist_delete(isc_log_t *lctx,
isc_mem_t *mem;
REQUIRE(ml != NULL);
REQUIRE(*ml != NULL);
iml = *ml;
if (iml == NULL) {
return (ISC_R_SUCCESS);
}
*ml = NULL;
REQUIRE(DNS_IPMLIST_VALID(iml));
......@@ -522,19 +519,19 @@ dns_c_ipmatchlist_delete(isc_log_t *lctx,
}
dns_c_ipmatchlist_t *
dns_c_ipmatchlist_attach(isc_log_t *lctx,
dns_c_ipmatchlist_t *ipml)
void
dns_c_ipmatchlist_attach(isc_log_t *lctx, dns_c_ipmatchlist_t *source,
dns_c_ipmatchlist_t **target)
{
(void) lctx;
REQUIRE(DNS_IPMLIST_VALID(ipml));
REQUIRE(DNS_IPMLIST_VALID(source));
INSIST(ipml->refcount > 0);
INSIST(source->refcount > 0);
ipml->refcount++;
return (ipml);
source->refcount++;
*target = source;
}
......@@ -586,7 +583,7 @@ dns_c_ipmatchlist_copy(isc_log_t *lctx, isc_mem_t *mem,
while (ime != NULL) {
result = dns_c_ipmatchelement_copy(lctx, mem, &ptr, ime);
if (result != ISC_R_SUCCESS) {
dns_c_ipmatchlist_delete(lctx, &newlist);
dns_c_ipmatchlist_detach(lctx, &newlist);
return (result);
}
......@@ -798,7 +795,7 @@ dns_c_iplist_new(isc_log_t *lctx,
isc_result_t
dns_c_iplist_delete(isc_log_t *lctx,
dns_c_iplist_detach(isc_log_t *lctx,
dns_c_iplist_t **list)
{
dns_c_iplist_t *l ;
......@@ -806,11 +803,9 @@ dns_c_iplist_delete(isc_log_t *lctx,
(void) lctx;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
}
REQUIRE(DNS_IPLIST_VALID(l));
INSIST(l->refcount > 0);
......@@ -828,18 +823,17 @@ dns_c_iplist_delete(isc_log_t *lctx,
}
dns_c_iplist_t *
dns_c_iplist_attach(isc_log_t *lctx,
dns_c_iplist_t *list)
void
dns_c_iplist_attach(isc_log_t *lctx, dns_c_iplist_t *source,
dns_c_iplist_t **target)
{
(void) lctx;
REQUIRE(DNS_IPLIST_VALID(list));
INSIST(list->refcount > 0);
REQUIRE(DNS_IPLIST_VALID(source));
INSIST(source->refcount > 0);
list->refcount++;
return (list);
source->refcount++;
*target = source;
}
......
......@@ -65,11 +65,9 @@ dns_c_kdeflist_delete(isc_log_t *lctx,
isc_result_t res;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
}
kd = ISC_LIST_HEAD(l->keydefs);
while (kd != NULL) {
......@@ -277,11 +275,9 @@ dns_c_kdef_delete(isc_log_t *lctx, dns_c_kdef_t **keydef)
(void)lctx;
REQUIRE(keydef != NULL);
REQUIRE(*keydef != NULL);
kd = *keydef;
if (kd == NULL) {
return (ISC_R_SUCCESS);
}
mem = kd->mylist->mem;
......@@ -451,11 +447,9 @@ dns_c_kidlist_delete(isc_log_t *lctx,
isc_result_t r;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
}
ki = ISC_LIST_HEAD(l->keyids);
while (ki != NULL) {
......@@ -483,11 +477,11 @@ keyid_delete(isc_log_t *lctx,
dns_c_kid_t *ki;
(void)lctx;
REQUIRE(keyid != NULL);
REQUIRE(*keyid != NULL);
ki = *keyid;
if (ki == NULL) {
return (ISC_R_SUCCESS);
}
isc_mem_free(ki->mylist->mem, ki->keyid);
isc_mem_put(ki->mylist->mem, ki, sizeof *ki);
......@@ -651,11 +645,9 @@ dns_c_pubkey_delete(isc_log_t *lctx,
(void)lctx;
REQUIRE(pubkey != NULL);
REQUIRE(*pubkey != NULL);
pkey = *pubkey;
if (pkey == NULL) {
return (ISC_R_SUCCESS);
}
if (pkey->key != NULL) {
isc_mem_free(pkey->mem, pkey->key);
......@@ -749,11 +741,9 @@ dns_c_tkeylist_delete(isc_log_t *lctx,
isc_result_t res;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
}
tkey = ISC_LIST_HEAD(l->tkeylist);
while (tkey != NULL) {
......@@ -922,11 +912,9 @@ dns_c_tkey_delete(isc_log_t *lctx,
dns_c_tkey_t *tk;
REQUIRE(tkey != NULL);
REQUIRE(*tkey != NULL);
tk = *tkey;
if (tk == NULL) {
return (ISC_R_SUCCESS);
}
isc_mem_free(tk->mem, tk->domain);
......
......@@ -91,11 +91,9 @@ dns_c_logginglist_delete(isc_log_t *lctx,
isc_result_t res;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
}
chan = ISC_LIST_HEAD(l->channels);
while (chan != NULL) {
......@@ -499,11 +497,9 @@ dns_c_logchan_delete(isc_log_t *lctx,
(void) lctx;
REQUIRE(channel != NULL);
REQUIRE(*channel != NULL);
logc = *channel;
if (logc == NULL) {
return (ISC_R_SUCCESS);
}
isc_mem_free(logc->mem, logc->name);
......@@ -1166,6 +1162,7 @@ dns_c_logcat_delete(isc_log_t *lctx,
(void) lctx;
REQUIRE(logcat != NULL);
REQUIRE(*logcat != NULL);
logc = *logcat;
if (logc == NULL) {
......
......@@ -66,23 +66,22 @@ dns_c_lstnon_delete(isc_log_t *lctx, dns_c_lstnon_t **listen)
isc_result_t r;
REQUIRE(listen != NULL);
REQUIRE(*listen != NULL);
lo = *listen;
if (lo == NULL) {
return (ISC_R_SUCCESS);
}
CHECK_LISTEN(lo);
r = dns_c_ipmatchlist_delete(lctx, &lo->iml);
if (r != ISC_R_SUCCESS) {
return (r);
}
if (lo->iml != NULL) {
r = dns_c_ipmatchlist_detach(lctx, &lo->iml);
} else
r = ISC_R_SUCCESS;
isc_mem_put(lo->mem, lo, sizeof *lo);
*listen = NULL;
return (ISC_R_SUCCESS);
return (r);
}
......@@ -94,11 +93,16 @@ dns_c_lstnon_setiml(isc_log_t *lctx, dns_c_lstnon_t *listen,
REQUIRE(listen != NULL);
REQUIRE(iml != NULL);
result = dns_c_ipmatchlist_delete(lctx, &listen->iml);
if (result != ISC_R_SUCCESS) {
return (result);
if (listen->iml != NULL) {
result = dns_c_ipmatchlist_detach(lctx, &listen->iml);
if (result != ISC_R_SUCCESS) {
return (result);
}
} else {
result = ISC_R_SUCCESS;
}
if (deepcopy) {
result = dns_c_ipmatchlist_copy(lctx, listen->mem,
......@@ -151,11 +155,9 @@ dns_c_lstnlist_delete(isc_log_t *lctx, dns_c_lstnlist_t **llist)
isc_result_t r;
REQUIRE(llist != NULL);
REQUIRE(*llist != NULL);
ll = *llist;
if (ll == NULL) {
return (ISC_R_SUCCESS);
}
CHECK_LLIST(ll);
......
......@@ -17,7 +17,7 @@
*/
#if !defined(lint) && !defined(SABER)
static char rcsid[] = "$Id: confparser.y,v 1.24 1999/11/02 15:49:42 brister Exp $";
static char rcsid[] = "$Id: confparser.y,v 1.25 1999/11/17 21:52:29 brister Exp $";
#endif /* not lint */
#include <config.h>
......@@ -2201,7 +2201,7 @@ address_match_simple: ip_address
}
}
dns_c_ipmatchlist_delete(logcontext, &$2);
dns_c_ipmatchlist_detach(logcontext, &$2);
$$ = ime;
}
......@@ -2504,7 +2504,7 @@ zone_stmt: L_ZONE domain_name optional_class L_LBRACE L_TYPE zone_type L_EOS
tmpres = dns_c_zonelist_addzone(logcontext,
currcfg->zlist, zone);
if (tmpres != ISC_R_SUCCESS) {
dns_c_zone_delete(logcontext, &zone);
dns_c_zone_detach(logcontext, &zone);
isc_log_write(logcontext, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG,
ISC_LOG_CRITICAL,
......@@ -2896,7 +2896,7 @@ zone_option: L_FILE L_QSTRING
default:
parser_error(ISC_FALSE,
"Failed to set zone forwarders.");
dns_c_iplist_delete(logcontext, &$3);
dns_c_iplist_detach(logcontext, &$3);
break;
}
}
......
......@@ -135,11 +135,9 @@ dns_c_rrsolist_delete(isc_log_t *lctx, dns_c_rrsolist_t **list)
isc_result_t r;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
l = *list;
if (l == NULL) {
return (ISC_R_SUCCESS);
}
elem = ISC_LIST_HEAD(l->elements);
while (elem != NULL) {
......@@ -169,11 +167,9 @@ dns_c_rrso_delete(isc_log_t *lctx, dns_c_rrso_t **order)
(void)lctx;
REQUIRE(order != NULL);
REQUIRE(*order != NULL);
oldo = *order;
if (oldo == NULL) {
return (ISC_R_SUCCESS);
}
REQUIRE(oldo->name != NULL);
isc_mem_free(oldo->mem, oldo->name);
......