Commit 8e1f35e1 authored by David Lawrence's avatar David Lawrence
Browse files

free ancestor memory allocated in addonlevel

parent e4bea1f7
......@@ -138,9 +138,10 @@ static inline void rotate_left(dns_rbtnode_t *node, dns_rbtnode_t *parent,
static inline void rotate_right(dns_rbtnode_t *node, dns_rbtnode_t *parent,
dns_rbtnode_t **rootp);
static dns_result_t dns_rbt_addonlevel(isc_mem_t *mctx,
static dns_result_t dns_rbt_addonlevel(dns_rbt_t *rbt,
dns_rbtnode_t *node,
dns_rbtnode_t **rootp);
dns_rbtnode_t **rootp,
node_chain_t *chain);
static void dns_rbt_deletefromlevel(dns_rbt_t *rbt,
dns_rbtnode_t *delete,
node_chain_t *chain);
......@@ -210,6 +211,7 @@ dns_rbt_addnode(dns_rbt_t *rbt, dns_name_t *name, dns_rbtnode_t **nodep) {
dns_name_t add_name, current_name, new_name, tmp_name;
int compared, add_labels, current_labels, keep_labels, start_label;
dns_result_t result;
node_chain_t chain;
REQUIRE(VALID_RBT(rbt));
REQUIRE(dns_name_isabsolute(name));
......@@ -439,7 +441,11 @@ dns_rbt_addnode(dns_rbt_t *rbt, dns_name_t *name, dns_rbtnode_t **nodep) {
result = create_node(rbt->mctx, &add_name, &new_node);
if (result == DNS_R_SUCCESS)
result = dns_rbt_addonlevel(rbt->mctx, new_node, root);
result = dns_rbt_addonlevel(rbt, new_node, root, &chain);
if (chain.ancestor_maxitems > 0)
isc_mem_put(rbt->mctx, chain.ancestors,
chain.ancestor_maxitems * sizeof(dns_rbtnode_t *));
if (result == DNS_R_SUCCESS)
*nodep = new_node;
......@@ -946,10 +952,9 @@ rotate_right(dns_rbtnode_t *node, dns_rbtnode_t *parent, dns_rbtnode_t **rootp)
* true red/black tree on a single level.
*/
static dns_result_t
dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
dns_rbtnode_t **rootp) {
dns_rbt_addonlevel(dns_rbt_t *rbt, dns_rbtnode_t *node, dns_rbtnode_t **rootp,
node_chain_t *chain) {
dns_rbtnode_t *current, *child, *root, *tmp, *parent, *grandparent;
node_chain_t chain;
dns_name_t add_name, current_name;
dns_offsets_t offsets;
int i;
......@@ -958,6 +963,9 @@ dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
REQUIRE(rootp != NULL);
REQUIRE(LEFT(node) == NULL && RIGHT(node) == NULL);
chain->ancestor_maxitems = 0;
chain->ancestor_count = 0;
root = *rootp;
if (root == NULL) {
MAKE_BLACK(node);
......@@ -968,19 +976,16 @@ dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
current = NULL;
child = root;
chain.ancestor_maxitems = 0;
chain.ancestor_count = 0;
dns_name_init(&add_name, offsets);
dns_rbt_namefromnode(node, &add_name);
dns_name_init(&current_name, NULL);
do {
if (chain.ancestor_count == chain.ancestor_maxitems &&
get_ancestor_mem(mctx, &chain) != DNS_R_SUCCESS)
if (chain->ancestor_count == chain->ancestor_maxitems &&
get_ancestor_mem(rbt->mctx, chain) != DNS_R_SUCCESS)
return (DNS_R_NOMEMORY);
ADD_ANCESTOR(&chain, current);
ADD_ANCESTOR(chain, current);
current = child;
......@@ -995,11 +1000,11 @@ dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
child = RIGHT(current);
} while (child != NULL);
if (chain.ancestor_count == chain.ancestor_maxitems &&
get_ancestor_mem(mctx, &chain) != DNS_R_SUCCESS)
if (chain->ancestor_count == chain->ancestor_maxitems &&
get_ancestor_mem(rbt->mctx, chain) != DNS_R_SUCCESS)
return (DNS_R_NOMEMORY);
ADD_ANCESTOR(&chain, current);
depth = chain.ancestor_count - 1;
ADD_ANCESTOR(chain, current);
depth = chain->ancestor_count - 1;
if (i < 0)
LEFT(current) = node;
......@@ -1007,11 +1012,11 @@ dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
RIGHT(current) = node;
MAKE_RED(node);
while (node != root && IS_RED(chain.ancestors[depth])) {
while (node != root && IS_RED(chain->ancestors[depth])) {
INSIST(depth > 0);
parent = chain.ancestors[depth];
grandparent = chain.ancestors[depth - 1];
parent = chain->ancestors[depth];
grandparent = chain->ancestors[depth - 1];
if (parent == LEFT(grandparent)) {
child = RIGHT(grandparent);
......@@ -1028,13 +1033,13 @@ dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
tmp = node;
node = parent;
parent = tmp;
chain.ancestors[depth] = parent;
chain->ancestors[depth] = parent;
}
MAKE_BLACK(parent);
MAKE_RED(grandparent);
INSIST(depth > 1);
rotate_right(grandparent,
chain.ancestors[depth - 2],
chain->ancestors[depth - 2],
&root);
}
} else {
......@@ -1052,13 +1057,13 @@ dns_rbt_addonlevel(isc_mem_t *mctx, dns_rbtnode_t *node,
tmp = node;
node = parent;
parent = tmp;
chain.ancestors[depth] = parent;
chain->ancestors[depth] = parent;
}
MAKE_BLACK(parent);
MAKE_RED(grandparent);
INSIST(depth > 1);
rotate_left(grandparent,
chain.ancestors[depth - 2],
chain->ancestors[depth - 2],
&root);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment