diff options
Diffstat (limited to 'main/stasis.c')
-rw-r--r-- | main/stasis.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/main/stasis.c b/main/stasis.c index 4d05f18e8..5eca791ef 100644 --- a/main/stasis.c +++ b/main/stasis.c @@ -686,15 +686,17 @@ struct stasis_forward *stasis_forward_cancel(struct stasis_forward *forward) from = forward->from_topic; to = forward->to_topic; - topic_lock_both(to, from); - AST_VECTOR_REMOVE_ELEM_UNORDERED(&to->upstream_topics, from, - AST_VECTOR_ELEM_CLEANUP_NOOP); + if (from && to) { + topic_lock_both(to, from); + AST_VECTOR_REMOVE_ELEM_UNORDERED(&to->upstream_topics, from, + AST_VECTOR_ELEM_CLEANUP_NOOP); - for (idx = 0; idx < AST_VECTOR_SIZE(&to->subscribers); ++idx) { - topic_remove_subscription(from, AST_VECTOR_GET(&to->subscribers, idx)); + for (idx = 0; idx < AST_VECTOR_SIZE(&to->subscribers); ++idx) { + topic_remove_subscription(from, AST_VECTOR_GET(&to->subscribers, idx)); + } + ao2_unlock(from); + ao2_unlock(to); } - ao2_unlock(from); - ao2_unlock(to); ao2_cleanup(forward); @@ -717,6 +719,11 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic, return NULL; } + /* Forwards to ourselves are implicit. */ + if (to_topic == from_topic) { + return ao2_bump(forward); + } + forward->from_topic = ao2_bump(from_topic); forward->to_topic = ao2_bump(to_topic); |