From: Stephan Bosch Date: Mon, 30 Sep 2019 08:30:25 +0000 (+0200) Subject: iputils.hh: NetmaskTree: Initialize TreeNode::node immediately. X-Git-Tag: auth-4.3.0-beta2~20^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=956c6dc4939f7a1457cf2bbbf99a6f97ac4f460e;p=thirdparty%2Fpdns.git iputils.hh: NetmaskTree: Initialize TreeNode::node immediately. Later commit relies on this. --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 0048714b32..c10033a6ea 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -653,7 +653,8 @@ private: */ class TreeNode : boost::noncopyable { public: - explicit TreeNode(int bits) noexcept : parent(nullptr),d_bits(bits) { + explicit TreeNode(int bits) noexcept : + parent(nullptr), node(new node_type()), assigned(false), d_bits(bits) { } // node; + bool assigned; //left || node->right || node->node)) { + // only cleanup this node if it has no children and node not assigned + if (!(node->left || node->right || node->assigned)) { // get parent node ptr TreeNode* pparent = node->parent; // delete this node @@ -736,8 +738,7 @@ public: //make_left(); } - // only create node if not yet assigned - if (!node->node) { - node->node = unique_ptr(new node_type()); - _nodes.insert(node->node.get()); + node_type* value = node->node.get(); + + // only insert value into set if not assigned before + if (!node->assigned) { + _nodes.insert(value); + node->assigned = true; } - value = node->node.get(); // assign key value->first = key; @@ -810,7 +812,7 @@ public: int bits = 0; for(; bits < max_bits; bits++) { // ...we keep track of last non-empty node - if (node->node) ret = node->node.get(); + if (node->assigned) ret = node->node.get(); bool val = value.getBit(-1-bits); // ...and we don't create left/right hand if (val) { @@ -823,7 +825,7 @@ public: } } // needed if we did not find one in loop - if (node->node) ret = node->node.get(); + if (node->assigned) ret = node->node.get(); // this can be nullptr. return ret; @@ -853,7 +855,8 @@ public: } if (node) { _nodes.erase(node->node.get()); - node->node.reset(); + node->assigned = false; + node->node->second = value_type(); if (d_cleanup_tree) cleanup_tree(node);