diff --git a/lib/dns/config/confacl.c b/lib/dns/config/confacl.c index 480e89c012..6055182d4e 100644 --- a/lib/dns/config/confacl.c +++ b/lib/dns/config/confacl.c @@ -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); diff --git a/lib/dns/config/confctl.c b/lib/dns/config/confctl.c index b1cad35ad2..e944f9f4a1 100644 --- a/lib/dns/config/confctl.c +++ b/lib/dns/config/confctl.c @@ -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: diff --git a/lib/dns/config/confctx.c b/lib/dns/config/confctx.c index f1152b777d..1c8a36437f 100644 --- a/lib/dns/config/confctx.c +++ b/lib/dns/config/confctx.c @@ -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); } diff --git a/lib/dns/config/confip.c b/lib/dns/config/confip.c index 74c0b7146b..c10a711dcf 100644 --- a/lib/dns/config/confip.c +++ b/lib/dns/config/confip.c @@ -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; } diff --git a/lib/dns/config/confkeys.c b/lib/dns/config/confkeys.c index 2b54f9b733..51e392d6c4 100644 --- a/lib/dns/config/confkeys.c +++ b/lib/dns/config/confkeys.c @@ -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); diff --git a/lib/dns/config/conflog.c b/lib/dns/config/conflog.c index 9a6825c7f6..cb7a93933d 100644 --- a/lib/dns/config/conflog.c +++ b/lib/dns/config/conflog.c @@ -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) { diff --git a/lib/dns/config/conflsn.c b/lib/dns/config/conflsn.c index 953bc9291d..a481b6aa93 100644 --- a/lib/dns/config/conflsn.c +++ b/lib/dns/config/conflsn.c @@ -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); diff --git a/lib/dns/config/confparser.y b/lib/dns/config/confparser.y index 40d137e64d..59a47b727d 100644 --- a/lib/dns/config/confparser.y +++ b/lib/dns/config/confparser.y @@ -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 @@ -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; } } diff --git a/lib/dns/config/confrrset.c b/lib/dns/config/confrrset.c index 198a4f6fa7..79da589a15 100644 --- a/lib/dns/config/confrrset.c +++ b/lib/dns/config/confrrset.c @@ -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); diff --git a/lib/dns/config/confserv.c b/lib/dns/config/confserv.c index 5c7a777723..c591538745 100644 --- a/lib/dns/config/confserv.c +++ b/lib/dns/config/confserv.c @@ -70,11 +70,9 @@ dns_c_srvlist_delete(isc_log_t *lctx, dns_c_srvlist_t **list) isc_result_t r; REQUIRE(list != NULL); + REQUIRE(*list != NULL); l = *list; - if (l == NULL) { - return (ISC_R_SUCCESS); - } server = ISC_LIST_HEAD(l->elements); while (server != NULL) { @@ -199,15 +197,15 @@ dns_c_srv_delete(isc_log_t *lctx, dns_c_srv_t **server) isc_mem_t *mem; REQUIRE(server != NULL); + REQUIRE(*server != NULL); serv = *server; - if (serv == NULL) { - return (ISC_R_SUCCESS); - } mem = serv->mem; serv->mem = NULL; - dns_c_kidlist_delete(lctx, &serv->keys); + + if (serv->keys != NULL) + dns_c_kidlist_delete(lctx, &serv->keys); isc_mem_put(mem, serv, sizeof *serv); diff --git a/lib/dns/config/confview.c b/lib/dns/config/confview.c index 299ea75fe7..47087e5e94 100644 --- a/lib/dns/config/confview.c +++ b/lib/dns/config/confview.c @@ -64,11 +64,9 @@ dns_c_viewtable_delete(isc_log_t *lctx, dns_c_viewtable_t *table; REQUIRE(viewtable != NULL); + REQUIRE(*viewtable != NULL); table = *viewtable; - if (table == NULL) { - return (ISC_R_SUCCESS); - } *viewtable = NULL; dns_c_viewtable_clear(lctx, table); @@ -281,7 +279,7 @@ dns_c_view_setallowquery(isc_log_t *lctx, REQUIRE(ipml != NULL); if (view->allowquery != NULL) { - dns_c_ipmatchlist_delete(lctx, &view->allowquery); + dns_c_ipmatchlist_detach(lctx, &view->allowquery); } if (deepcopy) { @@ -332,16 +330,14 @@ dns_c_view_delete(isc_log_t *lctx, dns_c_view_t *view; REQUIRE(viewptr != NULL); - - if (*viewptr == NULL) { - return (ISC_R_SUCCESS); - } + REQUIRE(*viewptr != NULL); view = *viewptr; isc_mem_free(view->mem, view->name); - dns_c_ipmatchlist_delete(lctx, &view->allowquery); + if (view->allowquery != NULL) + dns_c_ipmatchlist_detach(lctx, &view->allowquery); isc_mem_put(view->mem, view, sizeof *view); diff --git a/lib/dns/config/confzone.c b/lib/dns/config/confzone.c index 2cb15651e8..0a6dbeb729 100644 --- a/lib/dns/config/confzone.c +++ b/lib/dns/config/confzone.c @@ -151,11 +151,9 @@ dns_c_zonelist_delete(isc_log_t *lctx, dns_c_zonelist_t **zlist) isc_result_t res; REQUIRE(zlist != NULL); + REQUIRE(*zlist != NULL); list = *zlist; - if (list == NULL) { - return (ISC_R_SUCCESS); - } zoneelem = ISC_LIST_HEAD(list->zones); while (zoneelem != NULL) { @@ -276,7 +274,7 @@ dns_c_zonelist_rmbyname(isc_log_t *lctx, dns_c_zonelist_t *zlist, if (zoneelem != NULL) { ISC_LIST_UNLINK(zlist->zones, zoneelem, next); - res = dns_c_zone_delete(lctx, &zoneelem->thezone); + res = dns_c_zone_detach(lctx, &zoneelem->thezone); isc_mem_put(zlist->mem, zoneelem, sizeof *zoneelem); } else { res = ISC_R_NOTFOUND; @@ -307,7 +305,7 @@ dns_c_zonelist_rmzone(isc_log_t *lctx, dns_c_zonelist_t *zlist, if (zoneelem != NULL) { ISC_LIST_UNLINK(zlist->zones, zoneelem, next); - res = dns_c_zone_delete(lctx, &zoneelem->thezone); + res = dns_c_zone_detach(lctx, &zoneelem->thezone); isc_mem_put(zlist->mem, zoneelem, sizeof *zoneelem); } else { res = ISC_R_NOTFOUND; @@ -439,11 +437,15 @@ dns_c_zone_new(isc_log_t *lctx, isc_mem_t *mem, isc_result_t -dns_c_zone_delete(isc_log_t *lctx, dns_c_zone_t **zone) +dns_c_zone_detach(isc_log_t *lctx, dns_c_zone_t **zone) { - dns_c_zone_t *zoneptr = *zone; + dns_c_zone_t *zoneptr; isc_result_t res = ISC_R_SUCCESS; + REQUIRE(zone != NULL); + REQUIRE(*zone != NULL); + + zoneptr = *zone; *zone = NULL; REQUIRE(zoneptr->refcount > 0); @@ -458,17 +460,17 @@ dns_c_zone_delete(isc_log_t *lctx, dns_c_zone_t **zone) void -dns_c_zone_attach(isc_log_t *lctx, dns_c_zone_t *zone, - dns_c_zone_t **newzone) +dns_c_zone_attach(isc_log_t *lctx, dns_c_zone_t *source, + dns_c_zone_t **target) { - REQUIRE(zone != NULL); - REQUIRE(newzone != NULL); + REQUIRE(source != NULL); + REQUIRE(target != NULL); (void) lctx; - zone->refcount++; + source->refcount++; - *newzone = zone; + *target = source; } @@ -2941,6 +2943,7 @@ zone_delete(isc_log_t *lctx, dns_c_zone_t **zone) isc_result_t res = ISC_R_SUCCESS; REQUIRE(zone != NULL); + REQUIRE(*zone != NULL); z = *zone; @@ -2986,10 +2989,17 @@ master_zone_clear(isc_log_t *lctx, isc_mem_t *mem, dns_c_masterzone_t *mzone) isc_mem_free(mem, mzone->file); } - dns_c_ipmatchlist_delete(lctx, &mzone->allow_update); - dns_c_ipmatchlist_delete(lctx, &mzone->allow_query); - dns_c_ipmatchlist_delete(lctx, &mzone->allow_transfer); - dns_c_iplist_delete(lctx, &mzone->also_notify); + if (mzone->allow_update != NULL) + dns_c_ipmatchlist_detach(lctx, &mzone->allow_update); + + if (mzone->allow_query != NULL) + dns_c_ipmatchlist_detach(lctx, &mzone->allow_query); + + if (mzone->allow_transfer != NULL) + dns_c_ipmatchlist_detach(lctx, &mzone->allow_transfer); + + if (mzone->also_notify != NULL) + dns_c_iplist_detach(lctx, &mzone->also_notify); if (mzone->ixfr_base != NULL) { isc_mem_free(mem, mzone->ixfr_base); @@ -2998,9 +3008,12 @@ master_zone_clear(isc_log_t *lctx, isc_mem_t *mem, dns_c_masterzone_t *mzone) if (mzone->ixfr_tmp != NULL) { isc_mem_free(mem, mzone->ixfr_tmp); } - - dns_c_pubkey_delete(lctx, &mzone->pubkey); - dns_c_iplist_delete(lctx, &mzone->forwarders); + + if (mzone->pubkey != NULL) + dns_c_pubkey_delete(lctx, &mzone->pubkey); + + if (mzone->forwarders != NULL) + dns_c_iplist_detach(lctx, &mzone->forwarders); return (ISC_R_SUCCESS); } @@ -3025,12 +3038,23 @@ slave_zone_clear(isc_log_t *lctx, isc_mem_t *mem, dns_c_slavezone_t *szone) isc_mem_free(mem, szone->ixfr_tmp); } - dns_c_iplist_delete(lctx, &szone->master_ips); - dns_c_ipmatchlist_delete(lctx, &szone->allow_update); - dns_c_ipmatchlist_delete(lctx, &szone->allow_query); - dns_c_ipmatchlist_delete(lctx, &szone->allow_transfer); - dns_c_iplist_delete(lctx, &szone->also_notify); - dns_c_iplist_delete(lctx, &szone->forwarders); + if (szone->master_ips != NULL) + dns_c_iplist_detach(lctx, &szone->master_ips); + + if (szone->allow_update != NULL) + dns_c_ipmatchlist_detach(lctx, &szone->allow_update); + + if (szone->allow_query != NULL) + dns_c_ipmatchlist_detach(lctx, &szone->allow_query); + + if (szone->allow_transfer != NULL) + dns_c_ipmatchlist_detach(lctx, &szone->allow_transfer); + + if (szone->also_notify != NULL) + dns_c_iplist_detach(lctx, &szone->also_notify); + + if (szone->forwarders != NULL) + dns_c_iplist_detach(lctx, &szone->forwarders); return (ISC_R_SUCCESS); } @@ -3048,10 +3072,18 @@ stub_zone_clear(isc_log_t *lctx, isc_mem_t *mem, dns_c_stubzone_t *tzone) isc_mem_free(mem, tzone->file); } - dns_c_iplist_delete(lctx, &tzone->master_ips); - dns_c_ipmatchlist_delete(lctx, &tzone->allow_update); - dns_c_ipmatchlist_delete(lctx, &tzone->allow_query); - dns_c_ipmatchlist_delete(lctx, &tzone->allow_transfer); + if (tzone->master_ips != NULL) + dns_c_iplist_detach(lctx, &tzone->master_ips); + + if (tzone->allow_update != NULL) + dns_c_ipmatchlist_detach(lctx, &tzone->allow_update); + + if (tzone->allow_query != NULL) + dns_c_ipmatchlist_detach(lctx, &tzone->allow_query); + + if (tzone->allow_transfer != NULL) + dns_c_ipmatchlist_detach(lctx, &tzone->allow_transfer); + return (ISC_R_SUCCESS); } @@ -3066,7 +3098,8 @@ forward_zone_clear(isc_log_t *lctx, isc_mem_t *mem, dns_c_forwardzone_t *fzone) (void) mem; /* lint happiness */ - dns_c_iplist_delete(lctx, &fzone->forwarders); + if (fzone->forwarders != NULL) + dns_c_iplist_detach(lctx, &fzone->forwarders); return (ISC_R_SUCCESS); } @@ -3099,7 +3132,7 @@ set_ipmatch_list_field(isc_log_t *lctx, isc_mem_t *mem, isc_result_t res; if (*dest != NULL) { - res = dns_c_ipmatchlist_delete(lctx, dest); + res = dns_c_ipmatchlist_detach(lctx, dest); if (res != ISC_R_SUCCESS) { return (res); } @@ -3124,7 +3157,7 @@ set_iplist_field(isc_log_t *lctx, isc_mem_t *mem, isc_result_t res; if (*dest != NULL) { - res = dns_c_iplist_delete(lctx, dest); + res = dns_c_iplist_detach(lctx, dest); if (res != ISC_R_SUCCESS) { return (res); } diff --git a/lib/dns/include/dns/confip.h b/lib/dns/include/dns/confip.h index 3b033cb1cd..fb39e789dc 100644 --- a/lib/dns/include/dns/confip.h +++ b/lib/dns/include/dns/confip.h @@ -193,10 +193,11 @@ isc_result_t dns_c_ipmatchindirect_new(isc_log_t *lctx, isc_result_t dns_c_ipmatchlist_new(isc_log_t *lctx, isc_mem_t *mem, dns_c_ipmatchlist_t **ptr); -isc_result_t dns_c_ipmatchlist_delete(isc_log_t *lctx, +isc_result_t dns_c_ipmatchlist_detach(isc_log_t *lctx, dns_c_ipmatchlist_t **ml); -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); isc_result_t dns_c_ipmatchlist_copy(isc_log_t *lctx, isc_mem_t *mem, dns_c_ipmatchlist_t **dest, @@ -216,13 +217,14 @@ isc_result_t dns_c_ipmatchlist_print(isc_log_t *lctx, isc_result_t dns_c_iplist_new(isc_log_t *lctx, isc_mem_t *mem, int length, dns_c_iplist_t **newlist); -isc_result_t dns_c_iplist_delete(isc_log_t *lctx, +isc_result_t dns_c_iplist_detach(isc_log_t *lctx, dns_c_iplist_t **list); isc_result_t dns_c_iplist_copy(isc_log_t *lctx, isc_mem_t *mem, dns_c_iplist_t **dest, dns_c_iplist_t *src); -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); isc_result_t dns_c_iplist_append(isc_log_t *lctx, dns_c_iplist_t *list, isc_sockaddr_t newaddr); diff --git a/lib/dns/include/dns/confzone.h b/lib/dns/include/dns/confzone.h index a1c110da81..1d0510ed55 100644 --- a/lib/dns/include/dns/confzone.h +++ b/lib/dns/include/dns/confzone.h @@ -246,9 +246,9 @@ isc_result_t dns_c_zone_new(isc_log_t *lctx, isc_mem_t *mem, dns_c_zonetype_t ztype, dns_rdataclass_t zclass, const char *name, const char *internalname, dns_c_zone_t **zone); -isc_result_t dns_c_zone_delete(isc_log_t *lctx, dns_c_zone_t **zone); -void dns_c_zone_attach(isc_log_t *lctx, dns_c_zone_t *zone, - dns_c_zone_t **newzone); +isc_result_t dns_c_zone_detach(isc_log_t *lctx, dns_c_zone_t **zone); +void dns_c_zone_attach(isc_log_t *lctx, dns_c_zone_t *source, + dns_c_zone_t **target); void dns_c_zone_print(isc_log_t *lctx, FILE *fp, int indent, dns_c_zone_t *zone); isc_result_t dns_c_zone_setfile(isc_log_t *lctx, dns_c_zone_t *zone, diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 16881d9dcd..f8ac09da98 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,7 +15,7 @@ * SOFTWARE. */ - /* $Id: zone.c,v 1.35 1999/10/30 01:53:37 gson Exp $ */ + /* $Id: zone.c,v 1.36 1999/11/17 21:52:32 brister Exp $ */ #include @@ -357,11 +357,11 @@ zone_free(dns_zone_t *zone) { zone->check_names = dns_c_severity_ignore; zone->pubkey = NULL; /* XXX detach */ if (zone->update_acl != NULL) - dns_c_ipmatchlist_delete(NULL, &zone->update_acl); + dns_c_ipmatchlist_detach(NULL, &zone->update_acl); if (zone->query_acl != NULL) - dns_c_ipmatchlist_delete(NULL, &zone->query_acl); + dns_c_ipmatchlist_detach(NULL, &zone->query_acl); if (zone->xfr_acl != NULL) - dns_c_ipmatchlist_delete(NULL, &zone->xfr_acl); + dns_c_ipmatchlist_detach(NULL, &zone->xfr_acl); if (dns_name_dynamic(&zone->origin)) dns_name_free(&zone->origin, zone->mctx); @@ -2445,21 +2445,21 @@ dns_zone_copy(isc_log_t *lctx, dns_c_ctx_t *ctx, dns_c_zone_t *czone, iresult = dns_c_zone_getallowupd(lctx, czone, &acl); if (iresult == ISC_R_SUCCESS) { dns_zone_setupdateacl(zone, acl); - dns_c_ipmatchlist_delete(lctx, &acl); + dns_c_ipmatchlist_detach(lctx, &acl); } else dns_zone_clearupdateacl(zone); iresult = dns_c_zone_getallowquery(lctx, czone, &acl); if (iresult == ISC_R_SUCCESS) { dns_zone_setqueryacl(zone, acl); - dns_c_ipmatchlist_delete(lctx, &acl); + dns_c_ipmatchlist_detach(lctx, &acl); } else dns_zone_clearqueryacl(zone); iresult = dns_c_zone_getallowtransfer(lctx, czone, &acl); if (iresult == ISC_R_SUCCESS) { dns_zone_setxfracl(zone, acl); - dns_c_ipmatchlist_delete(lctx, &acl); + dns_c_ipmatchlist_detach(lctx, &acl); } else dns_zone_clearxfracl(zone); @@ -2522,7 +2522,7 @@ dns_zone_copy(isc_log_t *lctx, dns_c_ctx_t *ctx, dns_c_zone_t *czone, iresult = dns_c_zone_getallowquery(lctx, czone, &acl); if (iresult == ISC_R_SUCCESS) { dns_zone_setqueryacl(zone, acl); - dns_c_ipmatchlist_delete(lctx, &acl); + dns_c_ipmatchlist_detach(lctx, &acl); } else dns_zone_clearqueryacl(zone); @@ -2580,7 +2580,7 @@ dns_zone_copy(isc_log_t *lctx, dns_c_ctx_t *ctx, dns_c_zone_t *czone, iresult = dns_c_zone_getallowquery(lctx, czone, &acl); if (iresult == ISC_R_SUCCESS) { dns_zone_setqueryacl(zone, acl); - dns_c_ipmatchlist_delete(lctx, &acl); + dns_c_ipmatchlist_detach(lctx, &acl); } else dns_zone_clearqueryacl(zone); @@ -2653,10 +2653,10 @@ dns_zone_setqueryacl(dns_zone_t *zone, dns_c_ipmatchlist_t *acl) { LOCK(&zone->lock); if (zone->query_acl != NULL) - dns_c_ipmatchlist_delete(NULL /* isc_log_t */, + dns_c_ipmatchlist_detach(NULL /* isc_log_t */, &zone->query_acl); - zone->query_acl = dns_c_ipmatchlist_attach(NULL /* isc_log_t */, - acl); + dns_c_ipmatchlist_attach(NULL /* isc_log_t */, + acl, &zone->query_acl); UNLOCK(&zone->lock); } @@ -2667,10 +2667,10 @@ dns_zone_setupdateacl(dns_zone_t *zone, dns_c_ipmatchlist_t *acl) { LOCK(&zone->lock); if (zone->update_acl != NULL) - dns_c_ipmatchlist_delete(NULL /* isc_log_t */, + dns_c_ipmatchlist_detach(NULL /* isc_log_t */, &zone->update_acl); - zone->update_acl = dns_c_ipmatchlist_attach(NULL /* isc_log_t */, - acl); + dns_c_ipmatchlist_attach(NULL /* isc_log_t */, + acl, &zone->update_acl); UNLOCK(&zone->lock); } @@ -2681,10 +2681,10 @@ dns_zone_setxfracl(dns_zone_t *zone, dns_c_ipmatchlist_t *acl) { LOCK(&zone->lock); if (zone->xfr_acl != NULL) - dns_c_ipmatchlist_delete(NULL /* isc_log_t */, + dns_c_ipmatchlist_detach(NULL /* isc_log_t */, &zone->xfr_acl); - zone->xfr_acl = dns_c_ipmatchlist_attach(NULL /* isc_log_t */, - acl); + dns_c_ipmatchlist_attach(NULL /* isc_log_t */, + acl, &zone->xfr_acl); UNLOCK(&zone->lock); } @@ -2719,7 +2719,7 @@ dns_zone_clearupdateacl(dns_zone_t *zone) { LOCK(&zone->lock); if (zone->update_acl != NULL) - dns_c_ipmatchlist_delete(NULL /* isc_log_t */, + dns_c_ipmatchlist_detach(NULL /* isc_log_t */, &zone->update_acl); UNLOCK(&zone->lock); } @@ -2731,7 +2731,7 @@ dns_zone_clearqueryacl(dns_zone_t *zone) { LOCK(&zone->lock); if (zone->query_acl != NULL) - dns_c_ipmatchlist_delete(NULL /* isc_log_t */, + dns_c_ipmatchlist_detach(NULL /* isc_log_t */, &zone->query_acl); UNLOCK(&zone->lock); } @@ -2743,7 +2743,7 @@ dns_zone_clearxfracl(dns_zone_t *zone) { LOCK(&zone->lock); if (zone->xfr_acl != NULL) - dns_c_ipmatchlist_delete(NULL /* isc_log_t */, + dns_c_ipmatchlist_detach(NULL /* isc_log_t */, &zone->xfr_acl); UNLOCK(&zone->lock); }