summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-03-20 22:07:48 +0100
committerYorhel <git@yorhel.nl>2012-03-20 22:07:48 +0100
commit97b1e238e7b991fb5276d608c1da82595dbaff69 (patch)
tree6c081007f780696177350f3536400e04ee1e6c74
parentd16390981ed9105d168980a8a2d6f2365167c754 (diff)
link: Fix refcounting of the returnpath for link with self-matching tuple
Not that return-paths are currently handled at all by links, but this would have been a potential (and hard to find) bug.
-rw-r--r--tanja.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/tanja.c b/tanja.c
index 6b9fafb..a0f5d5b 100644
--- a/tanja.c
+++ b/tanja.c
@@ -1041,8 +1041,6 @@ static void tn_node_unregsession(tn_node *n, tn_session *s) {
// The reference held on the tuple is passed to the node. So the following
// works without memory leaks:
// tn_session_send(.., tn_tuple_new(..), ..);
-//
-// TODO: don't send tuples back to the link it came from
static void tn_node_send(tn_node *n, tn_tuple *tup, tn_returnpath *rp, tn_link *src) {
mutex_lock(n->lock);
khiter_t k = kh_begin(n->regs);
@@ -1050,12 +1048,15 @@ static void tn_node_send(tn_node *n, tn_tuple *tup, tn_returnpath *rp, tn_link *
patternreg *r = kh_exist(n->regs, k) ? kh_val(n->regs, k) : NULL;
if(!r || !tn_tuple_match(r->pat, tup))
continue;
- if(rp && r->willreply)
- tn_returnpath_open(rp);
- if(r->type == 0)
+ if(r->type == 0) { // session
+ if(rp && r->willreply)
+ tn_returnpath_open(rp);
tn_session_recv(r->recipient, tup, r, r->willreply ? rp : NULL);
- else if(r->recipient != src)
+ } else if(r->recipient != src) { // link (and not the sender of the tuple)
+ if(rp)
+ tn_returnpath_open(rp);
tn_link_node_recv(r->recipient, tup, rp);
+ }
}
mutex_unlock(n->lock);