2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

Add isc_refcount_destroy() as appropriate

This commit is contained in:
Ondřej Surý
2019-07-23 08:27:30 -04:00
parent 4643ee04bd
commit fbf9856f43
13 changed files with 29 additions and 21 deletions

View File

@@ -314,8 +314,6 @@ cleanup_filelock:
static void
cache_free(dns_cache_t *cache) {
int i;
REQUIRE(VALID_CACHE(cache));
isc_refcount_destroy(&cache->references);
@@ -359,10 +357,9 @@ cache_free(dns_cache_t *cache) {
if (strcmp(cache->db_type, "rbt") == 0) {
extra = 1;
}
for (i = extra; i < cache->db_argc; i++) {
for (int i = extra; i < cache->db_argc; i++) {
if (cache->db_argv[i] != NULL) {
isc_mem_free(cache->mctx,
cache->db_argv[i]);
isc_mem_free(cache->mctx, cache->db_argv[i]);
}
}
isc_mem_put(cache->mctx, cache->db_argv,

View File

@@ -598,8 +598,7 @@ deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
dns_qid_t *qid;
REQUIRE(disp->port_table != NULL);
REQUIRE(portentry != NULL &&
isc_refcount_current(&portentry->refs) > 0);
REQUIRE(portentry != NULL);
if (isc_refcount_decrement(&portentry->refs) == 1) {
qid = DNS_QID(disp);
@@ -617,7 +616,6 @@ deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
* dispsock->portentry does not change in socket_search.
*/
*portentryp = NULL;
}
/*%

View File

@@ -431,16 +431,17 @@ incctx_destroy(isc_mem_t *mctx, dns_incctx_t *ictx) {
static void
loadctx_destroy(dns_loadctx_t *lctx) {
isc_result_t result;
REQUIRE(DNS_LCTX_VALID(lctx));
isc_refcount_destroy(&lctx->references);
lctx->magic = 0;
if (lctx->inc != NULL)
if (lctx->inc != NULL) {
incctx_destroy(lctx->mctx, lctx->inc);
}
if (lctx->f != NULL) {
result = isc_stdio_close(lctx->f);
isc_result_t result = isc_stdio_close(lctx->f);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_stdio_close() failed: %s",
@@ -449,8 +450,9 @@ loadctx_destroy(dns_loadctx_t *lctx) {
}
/* isc_lex_destroy() will close all open streams */
if (lctx->lex != NULL && !lctx->keep_lex)
if (lctx->lex != NULL && !lctx->keep_lex) {
isc_lex_destroy(&lctx->lex);
}
if (lctx->task != NULL) {
isc_task_detach(&lctx->task);

View File

@@ -517,6 +517,8 @@ static void
destroy(dns_sdb_t *sdb) {
dns_sdbimplementation_t *imp = sdb->implementation;
isc_refcount_destroy(&sdb->references);
if (imp->methods->destroy != NULL) {
MAYBE_LOCK(sdb);
imp->methods->destroy(sdb->zone, imp->driverdata,

View File

@@ -480,6 +480,8 @@ destroynode(dns_sdlznode_t *node) {
dns_db_t *db;
isc_mem_t *mctx;
isc_refcount_destroy(&node->references);
sdlz = node->sdlz;
mctx = sdlz->common.mctx;
@@ -504,7 +506,6 @@ destroynode(dns_sdlznode_t *node) {
dns_name_free(node->name, mctx);
isc_mem_put(mctx, node->name, sizeof(dns_name_t));
}
isc_refcount_destroy(&node->references);
node->magic = 0;
isc_mem_put(mctx, node, sizeof(dns_sdlznode_t));

View File

@@ -125,6 +125,7 @@ dns_stats_detach(dns_stats_t **statsp) {
*statsp = NULL;
if (isc_refcount_decrement(&stats->references) == 1) {
isc_refcount_destroy(&stats->references);
isc_stats_detach(&stats->counters);
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
}

View File

@@ -431,6 +431,7 @@ cleanup_ring(dns_tsig_keyring_t *ring)
static void
destroyring(dns_tsig_keyring_t *ring) {
isc_refcount_destroy(&ring->references);
dns_rbt_destroy(&ring->keys);
isc_rwlock_destroy(&ring->lock);
isc_mem_putanddetach(&ring->mctx, ring, sizeof(dns_tsig_keyring_t));
@@ -614,14 +615,16 @@ dns_tsigkeyring_dumpanddetach(dns_tsig_keyring_t **ringp, FILE *fp) {
node = NULL;
dns_rbtnodechain_current(&chain, &foundname, origin, &node);
tkey = node->data;
if (tkey != NULL && tkey->generated && tkey->expire >= now)
if (tkey != NULL && tkey->generated && tkey->expire >= now) {
dump_key(tkey, fp);
}
result = dns_rbtnodechain_next(&chain, &foundname,
origin);
if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) {
dns_rbtnodechain_invalidate(&chain);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
}
goto destroy;
}
}

View File

@@ -82,6 +82,7 @@ isc_stats_detach(isc_stats_t **statsp) {
*statsp = NULL;
if (isc_refcount_decrement(&stats->references) == 1) {
isc_refcount_destroy(&stats->references);
isc_mem_put(stats->mctx, stats->counters,
sizeof(isc__atomic_statcounter_t) *
stats->ncounters);

View File

@@ -238,11 +238,12 @@ task_finished(isc__task_t *task) {
REQUIRE(EMPTY(task->events));
REQUIRE(task->nevents == 0);
REQUIRE(EMPTY(task->on_shutdown));
REQUIRE(atomic_load(&task->references) == 0);
REQUIRE(task->state == task_state_done);
XTRACE("task_finished");
isc_refcount_destroy(&task->references);
LOCK(&manager->lock);
UNLINK(manager->tasks, task, link);
atomic_fetch_sub(&manager->tasks_count, 1);

View File

@@ -2358,9 +2358,7 @@ clientmgr_attach(ns_clientmgr_t *source, ns_clientmgr_t **targetp) {
static void
clientmgr_detach(ns_clientmgr_t **mp) {
ns_clientmgr_t *mgr = *mp;
int32_t oldrefs;
oldrefs = isc_refcount_decrement(&mgr->references);
INSIST(oldrefs > 0);
int32_t oldrefs = isc_refcount_decrement(&mgr->references);
isc_log_write(ns_lctx, NS_LOGCATEGORY_CLIENT,
NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(3),
@@ -2380,6 +2378,7 @@ clientmgr_destroy(ns_clientmgr_t *manager) {
MTRACE("clientmgr_destroy");
isc_refcount_destroy(&manager->references);
manager->magic = 0;
#if CLIENT_NMCTXS > 0

View File

@@ -300,6 +300,8 @@ static void
ns_interfacemgr_destroy(ns_interfacemgr_t *mgr) {
REQUIRE(NS_INTERFACEMGR_VALID(mgr));
isc_refcount_destroy(&mgr->references);
#ifdef USE_ROUTE_SOCKET
if (mgr->route != NULL)
isc_socket_detach(&mgr->route);

View File

@@ -76,6 +76,7 @@ ns_lib_init(void) {
void
ns_lib_shutdown(void) {
if (isc_refcount_decrement(&references) == 1) {
isc_refcount_destroy(&references);
if (ns_g_mctx != NULL) {
isc_mem_detach(&ns_g_mctx);
}