]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Properly call isc_refcount_destroy() immediately after isc_refcount_decrement() to...
authorOndřej Surý <ondrej@sury.org>
Fri, 27 Jul 2018 12:41:12 +0000 (14:41 +0200)
committerOndřej Surý <ondrej@sury.org>
Wed, 8 Aug 2018 07:49:06 +0000 (09:49 +0200)
17 files changed:
bin/tests/system/dyndb/driver/db.c
lib/dns/acl.c
lib/dns/catz.c
lib/dns/dnstap.c
lib/dns/iptable.c
lib/dns/keytable.c
lib/dns/nta.c
lib/dns/order.c
lib/dns/portlist.c
lib/dns/rbtdb.c
lib/dns/rpz.c
lib/dns/tsig.c
lib/dns/view.c
lib/dns/zone.c
lib/isccfg/aclconf.c
lib/isccfg/parser.c
lib/ns/server.c

index 892cd7062beb99622543603f21a2abe8cc344091..a64c3d76e44bba3858f5adf1eed2fbe63096faac 100644 (file)
@@ -90,8 +90,10 @@ detach(dns_db_t **dbp) {
        REQUIRE(VALID_SAMPLEDB(sampledb));
 
        isc_refcount_decrement(&sampledb->refs, &refs);
-       if (refs == 0)
+       if (refs == 0) {
+               isc_refcount_destroy(&sampledb->refs);
                free_sampledb(sampledb);
+       }
        *dbp = NULL;
 }
 
index 64dde801019e69203c5314daebb63d102f24a557..44f42a415f55b3a22b1f97357c07b997455ec184 100644 (file)
@@ -472,7 +472,6 @@ destroy(dns_acl_t *dacl) {
                isc_mem_free(dacl->mctx, dacl->name);
        if (dacl->iptable != NULL)
                dns_iptable_detach(&dacl->iptable);
-       isc_refcount_destroy(&dacl->refcount);
        dacl->magic = 0;
        isc_mem_putanddetach(&dacl->mctx, dacl, sizeof(*dacl));
 }
@@ -485,8 +484,10 @@ dns_acl_detach(dns_acl_t **aclp) {
        REQUIRE(DNS_ACL_VALID(acl));
 
        isc_refcount_decrement(&acl->refcount, &refs);
-       if (refs == 0)
+       if (refs == 0) {
+               isc_refcount_destroy(&acl->refcount);
                destroy(acl);
+       }
        *aclp = NULL;
 }
 
index 724420c1205b3443c5409943d3eb9d04f618e306..51b1ac90604cd545394ac8db2ef1d8219909d227 100644 (file)
@@ -249,10 +249,10 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
 
        isc_refcount_decrement(&entry->refs, &refs);
        if (refs == 0) {
+               isc_refcount_destroy(&entry->refs);
                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));
        }
 }
@@ -751,6 +751,7 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
        *zonep = NULL;
        isc_refcount_decrement(&zone->refs, &refs);
        if (refs == 0) {
+               isc_refcount_destroy(&zone->refs);
                if (zone->entries != NULL) {
                        result = isc_ht_iter_create(zone->entries, &iter);
                        INSIST(result == ISC_R_SUCCESS);
@@ -772,7 +773,6 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
                }
                mctx = zone->catzs->mctx;
                isc_timer_detach(&zone->updatetimer);
-               isc_refcount_destroy(&zone->refs);
                if (zone->db_registered == ISC_TRUE) {
                        result = dns_db_updatenotify_unregister(zone->db,
                                                    dns_catz_dbupdate_callback,
@@ -811,6 +811,7 @@ dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
        isc_refcount_decrement(&catzs->refs, &refs);
 
        if (refs == 0) {
+               isc_refcount_destroy(&catzs->refs);
                DESTROYLOCK(&catzs->lock);
                if (catzs->zones != NULL) {
                        result = isc_ht_iter_create(catzs->zones, &iter);
@@ -827,7 +828,6 @@ dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
                        INSIST(isc_ht_count(catzs->zones) == 0);
                        isc_ht_destroy(&catzs->zones);
                }
-               isc_refcount_destroy(&catzs->refs);
                isc_task_destroy(&catzs->updater);
                isc_mem_putanddetach(&catzs->mctx, catzs, sizeof(*catzs));
        }
index d4a974a5c5e5a11550f6cac60442af3892444038..078ab84e08cc5cb1890fee2b4d0897c3a62d1af6 100644 (file)
@@ -586,8 +586,10 @@ dns_dt_detach(dns_dtenv_t **envp) {
        *envp = NULL;
 
        isc_refcount_decrement(&env->refcount, &refs);
-       if (refs == 0)
+       if (refs == 0) {
+               isc_refcount_destroy(&env->refcount);
                destroy(env);
+       }
 }
 
 static isc_result_t
index ec0c2229d038810586fb0e73e15482fdbbf413c8..13d4451290a5d3e5c5ef700e20ce58d92acea2bb 100644 (file)
@@ -149,8 +149,10 @@ dns_iptable_detach(dns_iptable_t **tabp) {
        unsigned int refs;
        REQUIRE(DNS_IPTABLE_VALID(tab));
        isc_refcount_decrement(&tab->refcount, &refs);
-       if (refs == 0)
+       if (refs == 0) {
+               isc_refcount_destroy(&tab->refcount);
                destroy_iptable(tab);
+       }
        *tabp = NULL;
 }
 
@@ -164,7 +166,6 @@ destroy_iptable(dns_iptable_t *dtab) {
                dtab->radix = NULL;
        }
 
-       isc_refcount_destroy(&dtab->refcount);
        dtab->magic = 0;
        isc_mem_putanddetach(&dtab->mctx, dtab, sizeof(*dtab));
 }
index 4323ab235f2e7b7c589a30df4d78a287f22b0ef4..209eaa0ed836426c81259d9c89176875392cde34 100644 (file)
@@ -137,9 +137,8 @@ dns_keytable_detach(dns_keytable_t **keytablep) {
 
        isc_refcount_decrement(&keytable->references, &refs);
        if (refs == 0) {
-               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;
@@ -817,9 +816,10 @@ dns_keynode_detach(isc_mem_t *mctx, dns_keynode_t **keynode) {
        REQUIRE(VALID_KEYNODE(node));
        isc_refcount_decrement(&node->refcount, &refs);
        if (refs == 0) {
-               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;
index 4a4d078425adc143931f2b8a7c0ea2b5ae17ddff..8ab42527f555f3d14127517189c9a1bb7bfecae2 100644 (file)
@@ -71,6 +71,7 @@ nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
        *ntap = NULL;
        isc_refcount_decrement(&nta->refcount, &refs);
        if (refs == 0) {
+               isc_refcount_destroy(&nta->refcount);
                nta->magic = 0;
                if (nta->timer != NULL) {
                        (void) isc_timer_reset(nta->timer,
@@ -78,7 +79,6 @@ nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
                                               NULL, NULL, ISC_TRUE);
                        isc_timer_detach(&nta->timer);
                }
-               isc_refcount_destroy(&nta->refcount);
                if (dns_rdataset_isassociated(&nta->rdataset))
                        dns_rdataset_disassociate(&nta->rdataset);
                if (dns_rdataset_isassociated(&nta->sigrdataset))
index ccf61fcabc280c39dc16736c767e428513cd5348..4549959104ddd9827b1186e66ff9e6a24d831e17 100644 (file)
@@ -140,15 +140,14 @@ dns_order_detach(dns_order_t **orderp) {
        order = *orderp;
        REQUIRE(DNS_ORDER_VALID(order));
        isc_refcount_decrement(&order->references, &references);
-       *orderp = NULL;
-       if (references != 0)
-               return;
-
-       order->magic = 0;
-       while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
-               ISC_LIST_UNLINK(order->ents, ent, link);
-               isc_mem_put(order->mctx, ent, sizeof(*ent));
+       if (references == 0) {
+               isc_refcount_destroy(&order->references);
+               order->magic = 0;
+               while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
+                       ISC_LIST_UNLINK(order->ents, ent, link);
+                       isc_mem_put(order->mctx, ent, sizeof(*ent));
+               }
+               isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
        }
-       isc_refcount_destroy(&order->references);
-       isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
+       *orderp = NULL;
 }
index c90b89bd4bb7dae56743524b55e7a304d1cc636a..5e31b1a58394d5db0f7e17f1895cff5f3c8a702c 100644 (file)
@@ -241,8 +241,8 @@ dns_portlist_detach(dns_portlist_t **portlistp) {
        *portlistp = NULL;
        isc_refcount_decrement(&portlist->refcount, &count);
        if (count == 0) {
-               portlist->magic = 0;
                isc_refcount_destroy(&portlist->refcount);
+               portlist->magic = 0;
                if (portlist->list != NULL)
                        isc_mem_put(portlist->mctx, portlist->list,
                                    portlist->allocated *
index 96d7fb03199ce76dab9944fef52df3c5ad7df458..b223c624008f92dcfd921508bd6c4f2dda1c7fa9 100644 (file)
@@ -1018,10 +1018,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, isc_boolean_t log, isc_event_t *event) {
 
                isc_refcount_decrement(&rbtdb->current_version->references,
                                       &refs);
-               INSIST(refs == 0);
+               isc_refcount_destroy(&rbtdb->current_version->references);
                UNLINK(rbtdb->open_versions, rbtdb->current_version, link);
                isc_rwlock_destroy(&rbtdb->current_version->glue_rwlock);
-               isc_refcount_destroy(&rbtdb->current_version->references);
                isc_rwlock_destroy(&rbtdb->current_version->rwlock);
                isc_mem_put(rbtdb->common.mctx, rbtdb->current_version,
                            sizeof(rbtdb_version_t));
@@ -1235,8 +1234,9 @@ detach(dns_db_t **dbp) {
 
        isc_refcount_decrement(&rbtdb->references, &refs);
 
-       if (refs == 0)
+       if (refs == 0) {
                maybe_free_rbtdb(rbtdb);
+       }
 
        *dbp = NULL;
 }
index 851ecbc84cac0957fab60a33e90c59af02024669..dd8b8ba629cd4fef2ad8213263ae1ee0f6e61f5e 100644 (file)
@@ -2114,6 +2114,7 @@ dns_rpz_detach_rpzs(dns_rpz_zones_t **rpzsp) {
        if (refs != 0) {
                return;
        }
+       isc_refcount_destroy(&rpzs->refs);
 
        /*
         * Forget the last of view's rpz machinery after the last reference.
@@ -2140,7 +2141,6 @@ dns_rpz_detach_rpzs(dns_rpz_zones_t **rpzsp) {
        }
        DESTROYLOCK(&rpzs->maint_lock);
        isc_rwlock_destroy(&rpzs->search_lock);
-       isc_refcount_destroy(&rpzs->refs);
        isc_task_destroy(&rpzs->updater);
        isc_mem_putanddetach(&rpzs->mctx, rpzs, sizeof(*rpzs));
 }
index af3b2eb3c26eb251da59be70be3f7398634826f1..33be942acfe243c71ae52d0aef1068bd5e497ee0 100644 (file)
@@ -725,7 +725,6 @@ tsigkey_free(dns_tsigkey_t *key) {
                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));
 }
 
@@ -740,8 +739,10 @@ dns_tsigkey_detach(dns_tsigkey_t **keyp) {
        key = *keyp;
        isc_refcount_decrement(&key->refs, &refs);
 
-       if (refs == 0)
+       if (refs == 0) {
+               isc_refcount_destroy(&key->refs);
                tsigkey_free(key);
+       }
 
        *keyp = NULL;
 }
index 5b3e3608b9842368449362385dabe8c006612f02..4a3622ad55017ae737f88a8e080f812a17c13b6b 100644 (file)
@@ -540,7 +540,6 @@ destroy(dns_view_t *view) {
                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));
@@ -588,6 +587,8 @@ view_flushanddetach(dns_view_t **viewp, isc_boolean_t flush) {
        if (refs == 0) {
                dns_zone_t *mkzone = NULL, *rdzone = NULL;
 
+               isc_refcount_destroy(&view->references);
+
                LOCK(&view->lock);
                if (!RESSHUTDOWN(view))
                        dns_resolver_shutdown(view->resolver);
index 98147483d32e073dfa2963c7c76cc5531cd925ae..418983b57d9aefc32f764714ae4fdeb599ef69f9 100644 (file)
@@ -1253,7 +1253,6 @@ zone_free(dns_zone_t *zone) {
        /* 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));
@@ -5223,6 +5222,8 @@ dns_zone_detach(dns_zone_t **zonep) {
        isc_refcount_decrement(&zone->erefs, &refs);
 
        if (refs == 0) {
+               isc_refcount_destroy(&zone->erefs);
+
                LOCK_ZONE(zone);
                INSIST(zone != zone->raw);
                /*
index dc161ca958b657f12ce96a781704598bcc43c64c..09d35a709deeb3d24564232c4ea5e7a4b7136afe 100644 (file)
@@ -77,6 +77,7 @@ cfg_aclconfctx_detach(cfg_aclconfctx_t **actxp) {
 
        isc_refcount_decrement(&actx->references, &refs);
        if (refs == 0) {
+               isc_refcount_destroy(&actx->references);
                for (dacl = ISC_LIST_HEAD(actx->named_acl_cache);
                     dacl != NULL;
                     dacl = next)
index db1ec2e6bf9234816f6f06b4b7c8c683432c22ed..96c80b34886e9e79a21015d963a65c0cebd5c69c 100644 (file)
@@ -680,6 +680,7 @@ cfg_parser_destroy(cfg_parser_t **pctxp) {
 
        isc_refcount_decrement(&pctx->references, &refs);
        if (refs == 0) {
+               isc_refcount_destroy(&pctx->references);
                isc_lex_destroy(&pctx->lexer);
                /*
                 * Cleaning up open_files does not
@@ -3147,8 +3148,8 @@ cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **objp) {
 
        isc_refcount_decrement(&obj->references, &refs);
        if (refs == 0) {
-               obj->type->rep->free(pctx, obj);
                isc_refcount_destroy(&obj->references);
+               obj->type->rep->free(pctx, obj);
                isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
        }
        *objp = NULL;
index d57e2cf254440322c7fff576ae90012d7767e515..e522e6fa7ce94f26a80501dbdb4be42f855df656 100644 (file)
@@ -134,6 +134,8 @@ ns_server_detach(ns_server_t **sctxp) {
        if (refs == 0) {
                ns_altsecret_t *altsecret;
 
+               isc_refcount_destroy(&sctx->references);
+               
                sctx->magic = 0;
 
                while ((altsecret = ISC_LIST_HEAD(sctx->altsecrets)) != NULL) {