diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index a84af436fe..eff48e0af7 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -173,8 +173,6 @@ free_listener(controllistener_t *listener) { INSIST(listener->exiting); INSIST(ISC_LIST_EMPTY(listener->connections)); - isc_refcount_destroy(&listener->references); - REQUIRE(listener->sock == NULL); free_controlkeylist(&listener->keys, listener->mctx); diff --git a/lib/dns/adb.c b/lib/dns/adb.c index beab25b57d..c47b2219aa 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -1179,7 +1179,6 @@ destroy_adbentry(dns_adbentry_t *entry) { } isc_mutex_destroy(&entry->lock); - isc_refcount_destroy(&entry->references); isc_mem_put(adb->mctx, entry, sizeof(*entry)); dec_adbstats(adb, dns_adbstats_entriescnt); @@ -1963,7 +1962,6 @@ destroy(dns_adb_t *adb) { isc_mem_detach(&adb->hmctx); isc_mutex_destroy(&adb->lock); - isc_refcount_destroy(&adb->references); isc_stats_detach(&adb->stats); dns_resolver_detach(&adb->res); diff --git a/lib/dns/catz.c b/lib/dns/catz.c index 26be1ec9e1..92149db468 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -1020,7 +1020,6 @@ dns__catz_zone_destroy(dns_catz_zone_t *catz) { dns_catz_options_free(&catz->zoneoptions, mctx); dns_catz_zones_detach(&catz->catzs); - isc_refcount_destroy(&catz->references); isc_mem_put(mctx, catz, sizeof(*catz)); } @@ -1032,7 +1031,6 @@ dns__catz_zones_destroy(dns_catz_zones_t *catzs) { catzs->magic = 0; isc_mutex_destroy(&catzs->lock); - isc_refcount_destroy(&catzs->references); isc_mem_putanddetach(&catzs->mctx, catzs, sizeof(*catzs)); } diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 0b82990a1a..9871c15c34 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -414,8 +414,6 @@ dispentry_destroy(dns_dispentry_t *resp) { INSIST(disp->requests > 0); disp->requests--; - isc_refcount_destroy(&resp->references); - resp->magic = 0; INSIST(!ISC_LINK_LINKED(resp, plink)); @@ -1363,7 +1361,6 @@ dispatch_destroy(dns_dispatch_t *disp) { dns_dispatchmgr_t *mgr = disp->mgr; uint32_t tid = isc_tid(); - isc_refcount_destroy(&disp->references); disp->magic = 0; if (disp->socktype == isc_socktype_tcp) { diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index 99ffe5623a..10614431b3 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -104,7 +104,6 @@ static void destroy_keynode(dns_keynode_t *knode) { dns_rdata_t *rdata = NULL; - isc_refcount_destroy(&knode->references); isc_rwlock_destroy(&knode->rwlock); if (knode->dslist != NULL) { for (rdata = ISC_LIST_HEAD(knode->dslist->rdata); rdata != NULL; @@ -163,7 +162,6 @@ destroy_keytable(dns_keytable_t *keytable) { dns_qpread_destroy(keytable->table, &qpr); dns_qpmulti_destroy(&keytable->table); - isc_refcount_destroy(&keytable->references); isc_mem_putanddetach(&keytable->mctx, keytable, sizeof(*keytable)); } diff --git a/lib/dns/nametree.c b/lib/dns/nametree.c index ec297ca6f2..08140371c0 100644 --- a/lib/dns/nametree.c +++ b/lib/dns/nametree.c @@ -66,7 +66,6 @@ static dns_qpmethods_t qpmethods = { static void destroy_ntnode(dns_ntnode_t *node) { - isc_refcount_destroy(&node->references); if (node->bits != NULL) { isc_mem_cput(node->mctx, node->bits, node->bits[0], sizeof(char)); @@ -120,7 +119,6 @@ destroy_nametree(dns_nametree_t *nametree) { /* dns_qpread_destroy(nametree->table, &qpr); */ dns_qpmulti_destroy(&nametree->table); - isc_refcount_destroy(&nametree->references); isc_mem_putanddetach(&nametree->mctx, nametree, sizeof(*nametree)); } diff --git a/lib/dns/nta.c b/lib/dns/nta.c index 35ee03e8de..6df1a9f5ab 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -93,7 +93,6 @@ dns__nta_destroy(dns__nta_t *nta) { REQUIRE(nta->timer == NULL); nta->magic = 0; - isc_refcount_destroy(&nta->references); if (dns_rdataset_isassociated(&nta->rdataset)) { dns_rdataset_disassociate(&nta->rdataset); } @@ -140,7 +139,6 @@ dns_ntatable_create(dns_view_t *view, isc_loopmgr_t *loopmgr, static void dns__ntatable_destroy(dns_ntatable_t *ntatable) { - isc_refcount_destroy(&ntatable->references); ntatable->magic = 0; isc_rwlock_destroy(&ntatable->rwlock); dns_qpmulti_destroy(&ntatable->table); diff --git a/lib/dns/request.c b/lib/dns/request.c index 46affed3f1..dc8aaaec64 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -227,8 +227,6 @@ requestmgr_destroy(dns_requestmgr_t *requestmgr) { INSIST(atomic_load(&requestmgr->shuttingdown)); - isc_refcount_destroy(&requestmgr->references); - size_t nloops = isc_loopmgr_nloops(requestmgr->loopmgr); for (size_t i = 0; i < nloops; i++) { INSIST(ISC_LIST_EMPTY(requestmgr->requests[i])); @@ -973,8 +971,6 @@ req_destroy(dns_request_t *request) { req_log(ISC_LOG_DEBUG(3), "%s: request %p", __func__, request); - isc_refcount_destroy(&request->references); - /* * These should have been cleaned up before the * completion event was sent. diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index f65b7e4a92..700c531eab 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -998,8 +998,6 @@ resquery_destroy(resquery_t *query) { dns_dispatch_detach(&query->dispatch); } - isc_refcount_destroy(&query->references); - LOCK(&fctx->lock); atomic_fetch_sub_release(&fctx->nqueries, 1); UNLOCK(&fctx->lock); @@ -4309,8 +4307,6 @@ fctx_destroy(fetchctx_t *fctx) { FCTXTRACE("destroy"); - isc_refcount_destroy(&fctx->references); - fctx->magic = 0; res = fctx->res; @@ -9850,7 +9846,6 @@ static void dns_resolver__destroy(dns_resolver_t *res) { alternate_t *a = NULL; - isc_refcount_destroy(&res->references); REQUIRE(!atomic_load_acquire(&res->priming)); REQUIRE(res->primefetch == NULL); diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index ee4ed0613a..46dc8ef3a7 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -2088,8 +2088,6 @@ static void dns__rpz_zones_destroy(dns_rpz_zones_t *rpzs) { REQUIRE(rpzs->shuttingdown); - isc_refcount_destroy(&rpzs->references); - for (dns_rpz_num_t rpz_num = 0; rpz_num < DNS_RPZ_MAX_ZONES; ++rpz_num) { if (rpzs->zones[rpz_num] == NULL) { diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index 8b03b2dba6..b65c0b7baf 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -332,7 +332,6 @@ destroyring(dns_tsigkeyring_t *ring) { ring->magic = 0; - isc_refcount_destroy(&ring->references); isc_rwlock_destroy(&ring->lock); isc_mem_putanddetach(&ring->mctx, ring, sizeof(dns_tsigkeyring_t)); } diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 22a8991617..3a3da99cfb 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -1859,7 +1859,6 @@ xfrin_destroy(dns_xfrin_t *xfr) { /* Safe-guards */ REQUIRE(atomic_load(&xfr->shuttingdown)); - isc_refcount_destroy(&xfr->references); INSIST(xfr->shutdown_result != ISC_R_UNSET); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index bf49b693b4..82b4157585 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -5601,8 +5601,6 @@ closeversion: static void zone_destroy(dns_zone_t *zone) { - isc_refcount_destroy(&zone->references); - /* * Stop things being restarted after we cancel them below. */ diff --git a/lib/isc/include/isc/refcount.h b/lib/isc/include/isc/refcount.h index 8231233072..8524b04410 100644 --- a/lib/isc/include/isc/refcount.h +++ b/lib/isc/include/isc/refcount.h @@ -34,6 +34,8 @@ ISC_LANG_BEGINDECLS typedef atomic_uint_fast32_t isc_refcount_t; +#define ISC_REFCOUNT_INITIALIZER(a) (a) + /** \def isc_refcount_init(ref, n) * \brief Initialize the reference counter. * \param[in] ref pointer to reference counter. @@ -145,6 +147,7 @@ typedef atomic_uint_fast32_t isc_refcount_t; uint_fast32_t refs = \ isc_refcount_decrement(&ptr->references) - 1; \ if (refs == 0) { \ + isc_refcount_destroy(&ptr->references); \ destroy(ptr); \ } \ fprintf(stderr, \ @@ -170,6 +173,7 @@ typedef atomic_uint_fast32_t isc_refcount_t; uint_fast32_t refs = \ isc_refcount_decrement(&ptr->references) - 1; \ if (refs == 0) { \ + isc_refcount_destroy(&ptr->references); \ destroy(ptr); \ } \ fprintf(stderr, \ @@ -193,6 +197,7 @@ typedef atomic_uint_fast32_t isc_refcount_t; void name##_unref(name##_t *ptr) { \ REQUIRE(ptr != NULL); \ if (isc_refcount_decrement(&ptr->references) == 1) { \ + isc_refcount_destroy(&ptr->references); \ destroy(ptr); \ } \ } \ diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index de49192474..df9b687c7c 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -880,8 +880,6 @@ isc_nmhandle_is_stream(isc_nmhandle_t *handle) { static void nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle) { - isc_refcount_destroy(&handle->references); - handle->magic = 0; if (handle->dofree != NULL) { diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index a7c5915211..9d59ffc43d 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -313,8 +313,6 @@ isc_ratelimiter_shutdown(isc_ratelimiter_t *restrict rl) { static void ratelimiter_destroy(isc_ratelimiter_t *restrict rl) { - isc_refcount_destroy(&rl->references); - LOCK(&rl->lock); REQUIRE(rl->state == isc_ratelimiter_shuttingdown); UNLOCK(&rl->lock); diff --git a/lib/ns/client.c b/lib/ns/client.c index 58d5c48624..967b915b22 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -2383,8 +2383,6 @@ clientmgr_destroy_cb(void *arg) { manager->magic = 0; - isc_refcount_destroy(&manager->references); - isc_loop_detach(&manager->loop); dns_aclenv_detach(&manager->aclenv);