]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Inactive incorrectly incremented
authorMark Andrews <marka@isc.org>
Fri, 18 Dec 2020 02:31:07 +0000 (13:31 +1100)
committerMark Andrews <marka@isc.org>
Wed, 6 Jan 2021 05:33:32 +0000 (16:33 +1100)
It is possible to have two threads destroying an rbtdb at the same
time when detachnode() executes and removes the last reference to
a node between exiting being set to true for the node and testing
if the references are zero in maybe_free_rbtdb().  Move NODE_UNLOCK()
to after checking if references is zero to prevent detachnode()
changing the reference count too early.

(cherry picked from commit 859d2fdad6d1c6ff20083a4c463a929cbeb26438)

lib/dns/rbtdb.c

index 79c75fefa01aa4aeb761344a38190459d20750b7..ef4510960015082471b4d04b75a976a140ee25f3 100644 (file)
@@ -1257,11 +1257,11 @@ maybe_free_rbtdb(dns_rbtdb_t *rbtdb) {
        for (i = 0; i < rbtdb->node_lock_count; i++) {
                NODE_LOCK(&rbtdb->node_locks[i].lock, isc_rwlocktype_write);
                rbtdb->node_locks[i].exiting = true;
-               NODE_UNLOCK(&rbtdb->node_locks[i].lock, isc_rwlocktype_write);
                if (isc_refcount_current(&rbtdb->node_locks[i].references) == 0)
                {
                        inactive++;
                }
+               NODE_UNLOCK(&rbtdb->node_locks[i].lock, isc_rwlocktype_write);
        }
 
        if (inactive != 0) {