summaryrefslogtreecommitdiff
path: root/src/mtrie.cpp
diff options
context:
space:
mode:
authorStaffan Gimåker <staffan@spotify.com>2012-02-16 10:02:35 +0900
committerMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:02:35 +0900
commit0f49d62fb09878349ff1bc4440f2cdfcf71a9e42 (patch)
treea7b68c91561a04f3f345a848760d19ffa2c6b25c /src/mtrie.cpp
parent1b74e5d307e7f0eb64389e0734cad08ce8b55f81 (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/mtrie.cpp')
-rw-r--r--src/mtrie.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mtrie.cpp b/src/mtrie.cpp
index ad4978c..27adb08 100644
--- a/src/mtrie.cpp
+++ b/src/mtrie.cpp
@@ -42,8 +42,11 @@ xs::mtrie_t::mtrie_t () :
xs::mtrie_t::~mtrie_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])
@@ -174,6 +177,7 @@ void xs::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
if (next.node->is_redundant ()) {
delete next.node;
next.node = 0;
+ count = 0;
--live_nodes;
}
return;
@@ -182,13 +186,14 @@ void xs::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
// If there are multiple subnodes.
for (unsigned short c = 0; c != count; c++) {
(*buff_) [buffsize_] = min + c;
- if (next.table [c])
+ if (next.table [c]) {
next.table [c]->rm_helper (pipe_, buff_, buffsize_ + 1,
maxbuffsize_, func_, arg_);
- if (next.table [c]->is_redundant ()) {
- delete next.table [c];
- next.table [c] = 0;
- --live_nodes;
+ if (next.table [c]->is_redundant ()) {
+ delete next.table [c];
+ next.table [c] = 0;
+ --live_nodes;
+ }
}
}
}
@@ -221,8 +226,10 @@ bool xs::mtrie_t::rm_helper (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;
@@ -272,7 +279,7 @@ void xs::mtrie_t::match (unsigned char *data_, size_t size_,
}
}
-bool xs::mtrie_t::is_redundant() const
+bool xs::mtrie_t::is_redundant () const
{
return pipes.empty () && live_nodes == 0;
}