Tomas Hozza cfca69
commit 3a2ea636103eaf40404fb82f228605d384c36434
Tomas Hozza cfca69
Author: Mark Andrews <marka@isc.org>
Tomas Hozza cfca69
Date:   Tue Dec 17 09:08:59 2013 +1100
Tomas Hozza cfca69
Tomas Hozza cfca69
    3692.   [bug]           Two calls to dns_db_getoriginnode were fatal if there
Tomas Hozza cfca69
                            was no data at the node. [RT #35080]
Tomas Hozza cfca69
    
Tomas Hozza cfca69
    (cherry picked from commit 161e803a5608956271d8120be37a1b383d14b647)
Tomas Hozza cfca69
Tomas Hozza cfca69
diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c
Tomas Hozza cfca69
index 2dd4aa0..941b77e 100644
Tomas Hozza cfca69
--- a/lib/dns/rbtdb.c
Tomas Hozza cfca69
+++ b/lib/dns/rbtdb.c
Tomas Hozza cfca69
@@ -1638,8 +1638,11 @@ decrement_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node,
Tomas Hozza cfca69
 
Tomas Hozza cfca69
 	nodelock = &rbtdb->node_locks[bucket];
Tomas Hozza cfca69
 
Tomas Hozza cfca69
+#define KEEP_NODE(n, r) \
Tomas Hozza cfca69
+	((n)->data != NULL || (n)->down != NULL || (n) == (r)->origin_node)
Tomas Hozza cfca69
+
Tomas Hozza cfca69
 	/* Handle easy and typical case first. */
Tomas Hozza cfca69
-	if (!node->dirty && (node->data != NULL || node->down != NULL)) {
Tomas Hozza cfca69
+	if (!node->dirty && KEEP_NODE(node, rbtdb)) {
Tomas Hozza cfca69
 		dns_rbtnode_refdecrement(node, &nrefs);
Tomas Hozza cfca69
 		INSIST((int)nrefs >= 0);
Tomas Hozza cfca69
 		if (nrefs == 0) {
Tomas Hozza cfca69
@@ -1708,12 +1711,11 @@ decrement_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node,
Tomas Hozza cfca69
 	isc_refcount_decrement(&nodelock->references, &refs);
Tomas Hozza cfca69
 	INSIST((int)refs >= 0);
Tomas Hozza cfca69
 
Tomas Hozza cfca69
-	/*
Tomas Hozza cfca69
-	 * XXXDCL should this only be done for cache zones?
Tomas Hozza cfca69
-	 */
Tomas Hozza cfca69
-	if (node->data != NULL || node->down != NULL)
Tomas Hozza cfca69
+	if (KEEP_NODE(node, rbtdb))
Tomas Hozza cfca69
 		goto restore_locks;
Tomas Hozza cfca69
 
Tomas Hozza cfca69
+#undef KEEP_NODE
Tomas Hozza cfca69
+
Tomas Hozza cfca69
 	if (write_locked) {
Tomas Hozza cfca69
 		/*
Tomas Hozza cfca69
 		 * We can now delete the node.