From 0f49d62fb09878349ff1bc4440f2cdfcf71a9e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Staffan=20Gim=C3=A5ker?= Date: Thu, 16 Feb 2012 10:02:35 +0900 Subject: The cause behind the segfault was next.node being deleted but count still being non-zero. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Staffan Gimåker --- src/trie.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/trie.cpp') diff --git a/src/trie.cpp b/src/trie.cpp index 2a21a5f..baa5c8d 100644 --- a/src/trie.cpp +++ b/src/trie.cpp @@ -43,8 +43,11 @@ xs::trie_t::trie_t () : xs::trie_t::~trie_t () { - if (count == 1) + if (count == 1) { + xs_assert (next.node); delete next.node; + next.node = 0; + } else if (count > 1) { for (unsigned short i = 0; i != count; ++i) if (next.table [i]) @@ -154,8 +157,10 @@ bool xs::trie_t::rm (unsigned char *prefix_, size_t size_) if (next_node->is_redundant ()) { delete next_node; - if (count == 1) + if (count == 1) { next.node = 0; + count = 0; + } else next.table [c - min] = 0; --live_nodes; @@ -242,7 +247,7 @@ void xs::trie_t::apply_helper ( } } -bool xs::trie_t::is_redundant() const +bool xs::trie_t::is_redundant () const { return refcnt == 0 && live_nodes == 0; } -- cgit v1.2.3