[Asterisk-code-review] Fixed duplicated subscription adding (...asterisk[master])

sungtae kim asteriskteam at digium.com
Wed Mar 27 18:56:04 CDT 2019


sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11201


Change subject: Fixed duplicated subscription adding
......................................................................

Fixed duplicated subscription adding

Currently, when the stasis adding the subscription, it doesn't
check the existed subscriptions.

It could be possible to causing the duplicated subscription.

ASTERISK-28357

Change-Id: I00bd627e4cc21aba0535d2695460a04f06f6e699
---
M main/stasis.c
1 file changed, 7 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/11201/1

diff --git a/main/stasis.c b/main/stasis.c
index 7dd3893..9a0d4eb 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -315,6 +315,8 @@
 /*! The number of buckets to use for subscription statistics */
 #define SUBSCRIPTION_STATISTICS_BUCKETS 57
 
+#define TOPIC_SUBSCRIPTION_CMP(a, b) (!strcmp(a->uniqueid, b->uniqueid))
+
 /*! Container which stores statistics for topics */
 static struct ao2_container *topic_statistics;
 
@@ -1026,6 +1028,7 @@
 static int topic_add_subscription(struct stasis_topic *topic, struct stasis_subscription *sub)
 {
 	size_t idx;
+	struct stasis_subscription *tmp_subscription;
 
 	ao2_lock(topic);
 	/* The reference from the topic to the subscription is shared with
@@ -1034,7 +1037,10 @@
 	 *
 	 * If we bumped the refcount here, the owner would have to unsubscribe
 	 * and cleanup, which is a bit awkward. */
-	AST_VECTOR_APPEND(&topic->subscribers, sub);
+	tmp_subscription = AST_VECTOR_GET_CMP(&topic->subscribers, sub, TOPIC_SUBSCRIPTION_CMP);
+	if (!tmp_subscription) {
+		AST_VECTOR_APPEND(&topic->subscribers, sub);
+	}
 
 	for (idx = 0; idx < AST_VECTOR_SIZE(&topic->upstream_topics); ++idx) {
 		topic_add_subscription(

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11201
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I00bd627e4cc21aba0535d2695460a04f06f6e699
Gerrit-Change-Number: 11201
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190327/2f690ea2/attachment.html>


More information about the asterisk-code-review mailing list