summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:02:31 +0900
committerMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:02:31 +0900
commit1b74e5d307e7f0eb64389e0734cad08ce8b55f81 (patch)
tree48895dbc57914322eaf8f0bea639a027baca9adf
parentc1fc7c4a0ef0faf941a57e8eb6ffdc247ffb7129 (diff)
Fixes to xs::xpub_t::xread_activated
1. If the subscription is malformed, drop it silently. 2. Fixes a memory leak Signed-off-by: Staffan Gimåker <staffan@spotify.com> Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--src/xpub.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/xpub.cpp b/src/xpub.cpp
index f5520f7..bf73399 100644
--- a/src/xpub.cpp
+++ b/src/xpub.cpp
@@ -63,7 +63,14 @@ void xs::xpub_t::xread_activated (pipe_t *pipe_)
// Apply the subscription to the trie.
unsigned char *data = (unsigned char*) sub.data ();
size_t size = sub.size ();
- xs_assert (size > 0 && (*data == 0 || *data == 1));
+
+ // TODO: In the case of malformed subscription we will simply ignore
+ // it for now. However, we should close the connection instead.
+ if (size <= 0 || (*data == 0 && *data == 1)) {
+ sub.close ();
+ return;
+ }
+
bool unique;
if (*data == 0)
unique = subscriptions.rm (data + 1, size - 1, pipe_);
@@ -76,6 +83,7 @@ void xs::xpub_t::xread_activated (pipe_t *pipe_)
pending.push_back (blob_t ((unsigned char*) sub.data (),
sub.size ()));
}
+ sub.close ();
}
void xs::xpub_t::xwrite_activated (pipe_t *pipe_)