From: Sergej Kasumovic Date: Thu, 20 Jul 2017 13:08:05 +0000 (+0200) Subject: res_stasis_device_state: Unsubscribe should remove old subscriptions X-Git-Tag: 14.7.0-rc1~123^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12c1dbf3324902ea5d960ea16e968ce76189967a;p=thirdparty%2Fasterisk.git res_stasis_device_state: Unsubscribe should remove old subscriptions Case scenario with Applications ARI: * Once you subscribe to deviceState with Applications REST API, it will be added into subscription pool. * When you unsubscribe it will remove from the device_state_subscription hash table but not from the subscription pool. * When you subscribe again, it will add it to pool again. * Now you will have two subscriptions and you will receive same event twice. This fix should now remove deviceState subscription from pool and it should fix unsubscribe on deviceState. ASTERISK-27130 #close Change-Id: I718b70d770a086e39b4ddba4f69a3c616d4476c4 --- diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c index 8356283587..44cd03ffc7 100644 --- a/res/res_stasis_device_state.c +++ b/res/res_stasis_device_state.c @@ -108,7 +108,6 @@ static int device_state_subscriptions_cmp(void *obj, void *arg, int flags) static void device_state_subscription_destroy(void *obj) { struct device_state_subscription *sub = obj; - sub->sub = stasis_unsubscribe_and_join(sub->sub); ast_string_field_free_memory(sub); } @@ -154,6 +153,9 @@ static struct device_state_subscription *find_device_state_subscription( static void remove_device_state_subscription( struct device_state_subscription *sub) { + if (sub->sub) { + sub->sub = stasis_unsubscribe_and_join(sub->sub); + } ao2_unlink_flags(device_state_subscriptions, sub, OBJ_NOLOCK); }