This properly orders clearing the freed pointer and calling isc_refcount_destroy
as early as possible to have ability to put proper memory barrier when cleaning
up reference counting.
static void
detach(dns_db_t **dbp) {
+ REQUIRE(dbp != NULL && VALID_SAMPLEDB((sampledb_t *)(*dbp)));
sampledb_t *sampledb = (sampledb_t *)(*dbp);
-
- REQUIRE(VALID_SAMPLEDB(sampledb));
+ *dbp = NULL;
if (isc_refcount_decrement(&sampledb->refs) == 1) {
free_sampledb(sampledb);
}
- *dbp = NULL;
}
/*
void
dns_acl_detach(dns_acl_t **aclp) {
+ REQUIRE(aclp != NULL && DNS_ACL_VALID(*aclp));
dns_acl_t *acl = *aclp;
-
- REQUIRE(DNS_ACL_VALID(acl));
+ *aclp = NULL;
if (isc_refcount_decrement(&acl->refcount) == 1) {
destroy(acl);
}
-
- *aclp = NULL;
}
void
dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
- dns_catz_entry_t *entry;
- isc_mem_t *mctx;
-
REQUIRE(entryp != NULL && *entryp != NULL);
-
- entry = *entryp;
-
- mctx = zone->catzs->mctx;
+ dns_catz_entry_t *entry = *entryp;
+ *entryp = NULL;
if (isc_refcount_decrement(&entry->refs) == 1) {
+ isc_refcount_destroy(&entry->refs);
+ isc_mem_t *mctx = zone->catzs->mctx;
dns_catz_options_free(&entry->opts, mctx);
if (dns_name_dynamic(&entry->name))
dns_name_free(&entry->name, mctx);
- isc_refcount_destroy(&entry->refs);
isc_mem_put(mctx, entry, sizeof(dns_catz_entry_t));
}
-
- *entryp = NULL;
}
bool
void
dns_catz_zone_detach(dns_catz_zone_t **zonep) {
- isc_result_t result;
- dns_catz_zone_t *zone;
- isc_ht_iter_t *iter = NULL;
- isc_mem_t *mctx;
-
REQUIRE(zonep != NULL && *zonep != NULL);
-
- zone = *zonep;
+ dns_catz_zone_t *zone = *zonep;
+ *zonep = NULL;
if (isc_refcount_decrement(&zone->refs) == 1) {
isc_refcount_destroy(&zone->refs);
if (zone->entries != NULL) {
+ isc_ht_iter_t *iter = NULL;
+ isc_result_t result;
result = isc_ht_iter_create(zone->entries, &iter);
INSIST(result == ISC_R_SUCCESS);
for (result = isc_ht_iter_first(iter);
INSIST(isc_ht_count(zone->entries) == 0);
isc_ht_destroy(&zone->entries);
}
- mctx = zone->catzs->mctx;
+ isc_mem_t *mctx = zone->catzs->mctx;
isc_timer_detach(&zone->updatetimer);
if (zone->db_registered == true) {
- result = dns_db_updatenotify_unregister(zone->db,
- dns_catz_dbupdate_callback,
- zone->catzs);
- INSIST(result == ISC_R_SUCCESS);
+ INSIST(dns_db_updatenotify_unregister(
+ zone->db,
+ dns_catz_dbupdate_callback,
+ zone->catzs)
+ == ISC_R_SUCCESS);
}
if (zone->dbversion)
dns_db_closeversion(zone->db, &zone->dbversion,
zone->catzs = NULL;
isc_mem_put(mctx, zone, sizeof(dns_catz_zone_t));
}
-
- *zonep = NULL;
}
void
-dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
- dns_catz_zones_t *catzs;
- isc_ht_iter_t *iter = NULL;
- isc_result_t result;
- dns_catz_zone_t *zone;
-
+dns_catz_catzs_detach(dns_catz_zones_t **catzsp) {
+ REQUIRE(catzsp != NULL && *catzsp != NULL);
+ dns_catz_zones_t *catzs = *catzsp;
- REQUIRE(catzsp != NULL);
catzs = *catzsp;
- REQUIRE(catzs != NULL);
-
*catzsp = NULL;
+
if (isc_refcount_decrement(&catzs->refs) == 1) {
isc_refcount_destroy(&catzs->refs);
DESTROYLOCK(&catzs->lock);
if (catzs->zones != NULL) {
+ isc_ht_iter_t *iter = NULL;
+ isc_result_t result;
result = isc_ht_iter_create(catzs->zones, &iter);
INSIST(result == ISC_R_SUCCESS);
for (result = isc_ht_iter_first(iter);
result == ISC_R_SUCCESS;)
{
+ dns_catz_zone_t *zone;
isc_ht_iter_current(iter, (void **) &zone);
result = isc_ht_iter_delcurrent_next(iter);
dns_catz_zone_detach(&zone);
void
dns_dt_detach(dns_dtenv_t **envp) {
- dns_dtenv_t *env;
-
REQUIRE(envp != NULL && VALID_DTENV(*envp));
-
- env = *envp;
+ dns_dtenv_t *env = *envp;
+ *envp = NULL;
if (isc_refcount_decrement(&env->refcount) == 1) {
+ isc_refcount_destroy(&env->refcount);
destroy(env);
}
-
- *envp = NULL;
}
static isc_result_t
void
dst_key_free(dst_key_t **keyp) {
- isc_mem_t *mctx;
- dst_key_t *key;
-
REQUIRE(dst_initialized == true);
REQUIRE(keyp != NULL && VALID_KEY(*keyp));
-
- key = *keyp;
- mctx = key->mctx;
+ dst_key_t *key = *keyp;
+ *keyp = NULL;
if (isc_refcount_decrement(&key->refs) == 1) {
isc_refcount_destroy(&key->refs);
+ isc_mem_t *mctx = key->mctx;
if (key->keydata.generic != NULL) {
INSIST(key->func->destroy != NULL);
key->func->destroy(key);
isc_safe_memwipe(key, sizeof(*key));
isc_mem_putanddetach(&mctx, key, sizeof(*key));
}
- *keyp = NULL;
}
bool
void
dns_iptable_detach(dns_iptable_t **tabp) {
+ REQUIRE(tabp != NULL && DNS_IPTABLE_VALID(*tabp));
dns_iptable_t *tab = *tabp;
- REQUIRE(DNS_IPTABLE_VALID(tab));
+ *tabp = NULL;
if (isc_refcount_decrement(&tab->refcount) == 1) {
+ isc_refcount_destroy(&tab->refcount);
destroy_iptable(tab);
}
-
- *tabp = NULL;
}
static void
dtab->radix = NULL;
}
- isc_refcount_destroy(&dtab->refcount);
dtab->magic = 0;
isc_mem_putanddetach(&dtab->mctx, dtab, sizeof(*dtab));
}
void
dns_keytable_detach(dns_keytable_t **keytablep) {
- dns_keytable_t *keytable;
-
- /*
- * Detach *keytablep from its keytable.
- */
-
REQUIRE(keytablep != NULL && VALID_KEYTABLE(*keytablep));
-
- keytable = *keytablep;
+ dns_keytable_t *keytable = *keytablep;
+ *keytablep = NULL;
if (isc_refcount_decrement(&keytable->references) == 1) {
- INSIST(isc_refcount_current(&keytable->active_nodes) == 0);
- isc_refcount_destroy(&keytable->active_nodes);
isc_refcount_destroy(&keytable->references);
+ isc_refcount_destroy(&keytable->active_nodes);
dns_rbt_destroy(&keytable->table);
isc_rwlock_destroy(&keytable->rwlock);
keytable->magic = 0;
isc_mem_putanddetach(&keytable->mctx,
keytable, sizeof(*keytable));
}
- *keytablep = NULL;
}
/*%
REQUIRE(VALID_KEYTABLE(keytable));
REQUIRE(keynodep != NULL && VALID_KEYNODE(*keynodep));
- (void)isc_refcount_decrement(&keytable->active_nodes);
+ INSIST(isc_refcount_decrement(&keytable->active_nodes) > 0);
dns_keynode_detach(keytable->mctx, keynodep);
}
break;
}
}
- (void)isc_refcount_decrement(&keytable->active_nodes);
+ INSIST(isc_refcount_decrement(&keytable->active_nodes) > 0);
cleanup:
dns_rbtnodechain_invalidate(&chain);
void
dns_keynode_detach(isc_mem_t *mctx, dns_keynode_t **keynode) {
+ REQUIRE(keynode != NULL && VALID_KEYNODE(*keynode));
dns_keynode_t *node = *keynode;
- REQUIRE(VALID_KEYNODE(node));
+ *keynode = NULL;
+
if (isc_refcount_decrement(&node->refcount) == 1) {
- if (node->key != NULL)
- dst_key_free(&node->key);
isc_refcount_destroy(&node->refcount);
+ if (node->key != NULL) {
+ dst_key_free(&node->key);
+ }
isc_mem_put(mctx, node, sizeof(dns_keynode_t));
}
- *keynode = NULL;
}
void
static void
nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
+ REQUIRE(ntap != NULL && VALID_NTA(*ntap));
dns_nta_t *nta = *ntap;
-
- REQUIRE(VALID_NTA(nta));
+ *ntap = NULL;
if (isc_refcount_decrement(&nta->refcount) == 1) {
+ isc_refcount_destroy(&nta->refcount);
nta->magic = 0;
if (nta->timer != NULL) {
- (void) isc_timer_reset(nta->timer,
- isc_timertype_inactive,
- NULL, NULL, true);
+ (void)isc_timer_reset(nta->timer,
+ isc_timertype_inactive,
+ NULL, NULL, true);
isc_timer_detach(&nta->timer);
}
- isc_refcount_destroy(&nta->refcount);
- if (dns_rdataset_isassociated(&nta->rdataset))
+ if (dns_rdataset_isassociated(&nta->rdataset)) {
dns_rdataset_disassociate(&nta->rdataset);
- if (dns_rdataset_isassociated(&nta->sigrdataset))
+ }
+ if (dns_rdataset_isassociated(&nta->sigrdataset)) {
dns_rdataset_disassociate(&nta->sigrdataset);
+ }
if (nta->fetch != NULL) {
dns_resolver_cancelfetch(nta->fetch);
dns_resolver_destroyfetch(&nta->fetch);
}
isc_mem_put(mctx, nta, sizeof(dns_nta_t));
}
- *ntap = NULL;
}
static void
void
dns_order_detach(dns_order_t **orderp) {
+ REQUIRE(orderp != NULL && DNS_ORDER_VALID(*orderp));
dns_order_t *order;
- dns_order_ent_t *ent;
-
- REQUIRE(orderp != NULL);
order = *orderp;
- REQUIRE(DNS_ORDER_VALID(order));
+ *orderp = NULL;
if (isc_refcount_decrement(&order->references) == 1) {
+ isc_refcount_destroy(&order->references);
order->magic = 0;
+ dns_order_ent_t *ent;
while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
ISC_LIST_UNLINK(order->ents, ent, link);
isc_mem_put(order->mctx, ent, sizeof(*ent));
}
- isc_refcount_destroy(&order->references);
isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
}
-
- *orderp = NULL;
}
void
dns_portlist_detach(dns_portlist_t **portlistp) {
- dns_portlist_t *portlist;
-
- REQUIRE(portlistp != NULL);
- portlist = *portlistp;
- REQUIRE(DNS_VALID_PORTLIST(portlist));
+ REQUIRE(portlistp != NULL && DNS_VALID_PORTLIST(*portlistp));
+ dns_portlist_t *portlist = *portlistp;
+ *portlistp = NULL;
if (isc_refcount_decrement(&portlist->refcount) == 1) {
portlist->magic = 0;
isc_mem_putanddetach(&portlist->mctx, portlist,
sizeof(*portlist));
}
- *portlistp = NULL;
}
if (rbtdb->current_version != NULL) {
- INSIST(isc_refcount_decrement(&rbtdb->current_version->references) == 1);
+ INSIST(isc_refcount_decrement(
+ &rbtdb->current_version->references)
+ == 1);
UNLINK(rbtdb->open_versions, rbtdb->current_version, link);
isc_rwlock_destroy(&rbtdb->current_version->glue_rwlock);
static void
detach(dns_db_t **dbp) {
+ REQUIRE(dbp != NULL && VALID_RBTDB((dns_rbtdb_t *)(*dbp)));
dns_rbtdb_t *rbtdb = (dns_rbtdb_t *)(*dbp);
-
- REQUIRE(VALID_RBTDB(rbtdb));
+ *dbp = NULL;
if (isc_refcount_decrement(&rbtdb->references) == 1) {
+ (void)isc_refcount_current(&rbtdb->references);
maybe_free_rbtdb(rbtdb);
}
-
- *dbp = NULL;
}
static void
} else
write_locked = true;
- isc_refcount_decrement(&nodelock->references);
+ INSIST(isc_refcount_decrement(&nodelock->references) > 0);
if (KEEP_NODE(node, rbtdb))
goto restore_locks;
else {
isc_event_free(&event);
if (isc_refcount_decrement(&rbtdb->references) == 1) {
+ (void)isc_refcount_current(&rbtdb->references);
maybe_free_rbtdb(rbtdb);
}
}
cur_version = rbtdb->current_version;
cur_ref = isc_refcount_decrement(&cur_version->references);
if (cur_ref == 1) {
+ (void)isc_refcount_current(&cur_version->references);
if (cur_version->serial == rbtdb->least_serial)
INSIST(EMPTY(cur_version->changed_list));
UNLINK(rbtdb->open_versions,
rbtdb->next_serial = 2;
rbtdb->current_version = allocate_version(mctx, 1, 1, false);
if (rbtdb->current_version == NULL) {
- isc_refcount_decrement(&rbtdb->references);
+ INSIST(isc_refcount_decrement(&rbtdb->references) > 0);
free_rbtdb(rbtdb, false, NULL);
return (ISC_R_NOMEMORY);
}
isc_mem_put(mctx, rbtdb->current_version,
sizeof(*rbtdb->current_version));
rbtdb->current_version = NULL;
- isc_refcount_decrement(&rbtdb->references);
+ INSIST(isc_refcount_decrement(&rbtdb->references) > 0);
free_rbtdb(rbtdb, false, NULL);
return (result);
}
dns_rbt_destroy(&zones->rbt);
cleanup_rbt:
- (void)isc_refcount_decrement(&zones->refs);
+ INSIST(isc_refcount_decrement(&zones->refs) > 0);
isc_refcount_destroy(&zones->refs);
DESTROYLOCK(&zones->maint_lock);
isc_timer_detach(&zone->updatetimer);
cleanup_timer:
- isc_refcount_decrement(&zone->refs);
+ INSIST(isc_refcount_decrement(&zone->refs) > 0);
isc_refcount_destroy(&zone->refs);
isc_mem_put(zone->rpzs->mctx, zone, sizeof(*zone));
*/
static void
rpz_detach(dns_rpz_zone_t **rpzp, dns_rpz_zones_t *rpzs) {
- dns_rpz_zone_t *rpz;
-
- rpz = *rpzp;
+ REQUIRE(rpzp != NULL && *rpzp != NULL);
+ dns_rpz_zone_t *rpz = *rpzp;
+ *rpzp = NULL;
if (isc_refcount_decrement(&rpz->refs) == 1) {
isc_refcount_destroy(&rpz->refs);
isc_mem_put(rpzs->mctx, rpz, sizeof(*rpz));
}
-
- *rpzp = NULL;
}
void
*/
void
dns_rpz_detach_rpzs(dns_rpz_zones_t **rpzsp) {
- dns_rpz_zones_t *rpzs;
- dns_rpz_zone_t *rpz;
- dns_rpz_num_t rpz_num;
-
- REQUIRE(rpzsp != NULL);
- rpzs = *rpzsp;
- REQUIRE(rpzs != NULL);
-
+ REQUIRE(rpzsp != NULL && *rpzsp != NULL);
+ dns_rpz_zones_t *rpzs = *rpzsp;
*rpzsp = NULL;
+
if (isc_refcount_decrement(&rpzs->refs) == 1) {
isc_refcount_destroy(&rpzs->refs);
-
/*
* Forget the last of view's rpz machinery after the last reference.
*/
- for (rpz_num = 0; rpz_num < DNS_RPZ_MAX_ZONES; ++rpz_num) {
- rpz = rpzs->zones[rpz_num];
+ for (dns_rpz_num_t rpz_num = 0;
+ rpz_num < DNS_RPZ_MAX_ZONES;
+ ++rpz_num)
+ {
+ dns_rpz_zone_t *rpz = rpzs->zones[rpz_num];
rpzs->zones[rpz_num] = NULL;
if (rpz != NULL) {
rpz_detach(&rpz, rpzs);
cleanup_refs:
tkey->magic = 0;
while (refs-- > 0) {
- (void)isc_refcount_decrement(&tkey->refs);
+ INSIST(isc_refcount_decrement(&tkey->refs) > 0);
}
isc_refcount_destroy(&tkey->refs);
dns_name_free(key->creator, key->mctx);
isc_mem_put(key->mctx, key->creator, sizeof(dns_name_t));
}
- isc_refcount_destroy(&key->refs);
isc_mem_putanddetach(&key->mctx, key, sizeof(dns_tsigkey_t));
}
void
dns_tsigkey_detach(dns_tsigkey_t **keyp) {
- dns_tsigkey_t *key;
-
- REQUIRE(keyp != NULL);
- REQUIRE(VALID_TSIG_KEY(*keyp));
-
- key = *keyp;
+ REQUIRE(keyp != NULL && VALID_TSIG_KEY(*keyp));
+ dns_tsigkey_t *key = *keyp;
+ *keyp = NULL;
if (isc_refcount_decrement(&key->refs) == 1) {
+ isc_refcount_destroy(&key->refs);
tsigkey_free(key);
}
-
- *keyp = NULL;
}
void
dns_tsigkeyring_detach(&view->dynamickeys);
cleanup_references:
- (void)isc_refcount_decrement(&view->references);
+ INSIST(isc_refcount_decrement(&view->references) > 0);
isc_refcount_destroy(&view->references);
if (view->fwdtable != NULL)
dns_badcache_destroy(&view->failcache);
DESTROYLOCK(&view->new_zone_lock);
DESTROYLOCK(&view->lock);
- isc_refcount_destroy(&view->references);
isc_mem_free(view->mctx, view->nta_file);
isc_mem_free(view->mctx, view->name);
isc_mem_putanddetach(&view->mctx, view, sizeof(*view));
static void
view_flushanddetach(dns_view_t **viewp, bool flush) {
- dns_view_t *view;
- bool done = false;
+ REQUIRE(viewp != NULL && DNS_VIEW_VALID(*viewp));
+ dns_view_t *view = *viewp;
+ *viewp = NULL;
- REQUIRE(viewp != NULL);
- view = *viewp;
- REQUIRE(DNS_VIEW_VALID(view));
+ if (flush) {
+ view->flush = flush;
+ }
- if (flush)
- view->flush = true;
+ bool done = false;
if (isc_refcount_decrement(&view->references) == 1) {
dns_zone_t *mkzone = NULL, *rdzone = NULL;
+ isc_refcount_destroy(&view->references);
LOCK(&view->lock);
- if (!RESSHUTDOWN(view))
+ if (!RESSHUTDOWN(view)) {
dns_resolver_shutdown(view->resolver);
- if (!ADBSHUTDOWN(view))
+ }
+ if (!ADBSHUTDOWN(view)) {
dns_adb_shutdown(view->adb);
- if (!REQSHUTDOWN(view))
+ }
+ if (!REQSHUTDOWN(view)) {
dns_requestmgr_shutdown(view->requestmgr);
+ }
if (view->zonetable != NULL) {
- if (view->flush)
+ if (view->flush) {
dns_zt_flushanddetach(&view->zonetable);
- else
+ } else {
dns_zt_detach(&view->zonetable);
+ }
}
if (view->managed_keys != NULL) {
mkzone = view->managed_keys;
view->managed_keys = NULL;
- if (view->flush)
+ if (view->flush) {
dns_zone_flush(mkzone);
+ }
}
if (view->redirect != NULL) {
rdzone = view->redirect;
UNLOCK(&view->lock);
/* Need to detach zones outside view lock */
- if (mkzone != NULL)
+ if (mkzone != NULL) {
dns_zone_detach(&mkzone);
+ }
- if (rdzone != NULL)
+ if (rdzone != NULL) {
dns_zone_detach(&rdzone);
+ }
}
*viewp = NULL;
- if (done)
+ if (done) {
destroy(view);
+ }
}
void
isc_stats_detach(&zone->gluecachestats);
free_erefs:
- (void)isc_refcount_decrement(&zone->erefs);
+ INSIST(isc_refcount_decrement(&zone->erefs) > 0);
isc_refcount_destroy(&zone->erefs);
ZONEDB_DESTROYLOCK(&zone->dblock);
/* last stuff */
ZONEDB_DESTROYLOCK(&zone->dblock);
DESTROYLOCK(&zone->lock);
- isc_refcount_destroy(&zone->erefs);
zone->magic = 0;
mctx = zone->mctx;
isc_mem_put(mctx, zone, sizeof(*zone));
void
dns_zone_detach(dns_zone_t **zonep) {
- dns_zone_t *zone;
- dns_zone_t *raw = NULL;
- dns_zone_t *secure = NULL;
- bool free_now = false;
-
REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
+ dns_zone_t *zone = *zonep;
+ *zonep = NULL;
- zone = *zonep;
-
+ bool free_now = false;
+ dns_zone_t *raw = NULL;
+ dns_zone_t *secure = NULL;
if (isc_refcount_decrement(&zone->erefs) == 1) {
+ isc_refcount_destroy(&zone->erefs);
+
LOCK_ZONE(zone);
INSIST(zone != zone->raw);
/*
}
UNLOCK_ZONE(zone);
}
- *zonep = NULL;
if (free_now) {
- if (raw != NULL)
+ if (raw != NULL) {
dns_zone_detach(&raw);
- if (secure != NULL)
+ }
+ if (secure != NULL) {
dns_zone_idetach(&secure);
+ }
zone_free(zone);
}
}
ctx->malloced -= DEBUG_TABLE_COUNT * sizeof(debuglist_t);
}
#endif
- isc_refcount_destroy(&ctx->references);
if (ctx->checkfree) {
for (i = 0; i <= ctx->max_size; i++) {
void
isc__mem_detach(isc_mem_t **ctxp) {
- isc__mem_t *ctx;
-
- REQUIRE(ctxp != NULL);
- ctx = (isc__mem_t *)*ctxp;
- REQUIRE(VALID_CONTEXT(ctx));
+ REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
+ isc__mem_t *ctx = (isc__mem_t *)*ctxp;
+ *ctxp = NULL;
if (isc_refcount_decrement(&ctx->references) == 1) {
+ isc_refcount_destroy(&ctx->references);
destroy(ctx);
}
-
- *ctxp = NULL;
}
/*
void
isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
- isc__mem_t *ctx;
- size_info *si;
- size_t oldsize;
-
- REQUIRE(ctxp != NULL);
- ctx = (isc__mem_t *)*ctxp;
- REQUIRE(VALID_CONTEXT(ctx));
+ REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
REQUIRE(ptr != NULL);
-
- /*
- * Must be before mem_putunlocked() as ctxp is usually within
- * [ptr..ptr+size).
- */
+ isc__mem_t *ctx = (isc__mem_t *)*ctxp;
*ctxp = NULL;
if (ISC_UNLIKELY((isc_mem_debugging &
(ISC_MEM_DEBUGSIZE|ISC_MEM_DEBUGCTX)) != 0))
{
if ((isc_mem_debugging & ISC_MEM_DEBUGSIZE) != 0) {
- si = &(((size_info *)ptr)[-1]);
- oldsize = si->u.size - ALIGNMENT_SIZE;
+ size_info *si = &(((size_info *)ptr)[-1]);
+ size_t oldsize = si->u.size - ALIGNMENT_SIZE;
if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)
oldsize -= ALIGNMENT_SIZE;
INSIST(oldsize == size);
}
isc__mem_free((isc_mem_t *)ctx, ptr FLARG_PASS);
- if (isc_refcount_decrement(&ctx->references) == 1) {
- destroy(ctx);
- }
-
- return;
+ goto destroy;
}
MCTXLOCK(ctx, &ctx->lock);
}
MCTXUNLOCK(ctx, &ctx->lock);
+destroy:
if (isc_refcount_decrement(&ctx->references) == 1) {
+ isc_refcount_destroy(&ctx->references);
destroy(ctx);
}
}
print_active(ctx, stderr);
}
#else
- (void)isc_refcount_decrement(&ctx->references);
+ INSIST(isc_refcount_decrement(&ctx->references) == 1);
#endif
isc_refcount_destroy(&ctx->references);
destroy(ctx);
static void
_deref_prefix(isc_prefix_t *prefix) {
- if (prefix == NULL)
- return;
-
- if (isc_refcount_decrement(&prefix->refcount) == 1) {
- isc_refcount_destroy(&prefix->refcount);
- isc_mem_putanddetach(&prefix->mctx, prefix,
- sizeof(isc_prefix_t));
+ if (prefix != NULL) {
+ if (isc_refcount_decrement(&prefix->refcount) == 1) {
+ isc_refcount_destroy(&prefix->refcount);
+ isc_mem_putanddetach(&prefix->mctx, prefix,
+ sizeof(isc_prefix_t));
+ }
}
}
parent->l = child;
}
}
-
-/*
-Local Variables:
-c-basic-offset: 4
-indent-tabs-mode: t
-End:
-*/
void
cfg_aclconfctx_detach(cfg_aclconfctx_t **actxp) {
- cfg_aclconfctx_t *actx;
- dns_acl_t *dacl, *next;
-
REQUIRE(actxp != NULL && *actxp != NULL);
-
- actx = *actxp;
+ cfg_aclconfctx_t *actx = *actxp;
+ *actxp = NULL;
if (isc_refcount_decrement(&actx->references) == 1) {
+ dns_acl_t *dacl, *next;
+ isc_refcount_destroy(&actx->references);
for (dacl = ISC_LIST_HEAD(actx->named_acl_cache);
dacl != NULL;
dacl = next)
}
isc_mem_putanddetach(&actx->mctx, actx, sizeof(*actx));
}
-
- *actxp = NULL;
}
/*
cfg_parser_t *pctx;
REQUIRE(pctxp != NULL && *pctxp != NULL);
-
pctx = *pctxp;
*pctxp = NULL;
*/
void
cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **objp) {
- cfg_obj_t *obj;
-
REQUIRE(objp != NULL && *objp != NULL);
REQUIRE(pctx != NULL);
- obj = *objp;
+ cfg_obj_t *obj = *objp;
+ *objp = NULL;
if (isc_refcount_decrement(&obj->references) == 1) {
obj->type->rep->free(pctx, obj);
isc_refcount_destroy(&obj->references);
isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
}
- *objp = NULL;
}
void
ns_server_detach(ns_server_t **sctxp) {
ns_server_t *sctx;
- REQUIRE(sctxp != NULL);
+ REQUIRE(sctxp != NULL && SCTX_VALID(*sctxp));
sctx = *sctxp;
- REQUIRE(SCTX_VALID(sctx));
+ *sctxp = NULL;
if (isc_refcount_decrement(&sctx->references) == 1) {
ns_altsecret_t *altsecret;
isc_mem_putanddetach(&sctx->mctx, sctx, sizeof(*sctx));
}
-
- *sctxp = NULL;
}
isc_result_t