diff options
author | Staffan Gimåker <staffan@spotify.com> | 2012-02-16 10:02:35 +0900 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-02-16 10:02:35 +0900 |
commit | 0f49d62fb09878349ff1bc4440f2cdfcf71a9e42 (patch) | |
tree | a7b68c91561a04f3f345a848760d19ffa2c6b25c /src/trie.cpp | |
parent | 1b74e5d307e7f0eb64389e0734cad08ce8b55f81 (diff) |
The cause behind the segfault was next.node being deleted but count still being non-zero.
Signed-off-by: Staffan Gimåker <staffan@spotify.com>
Diffstat (limited to 'src/trie.cpp')
-rw-r--r-- | src/trie.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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; } |