[Asterisk-code-review] Core/Stasis: Fix "FRACK!, Failed assertion bad magic number" happens ... (asterisk[16.5])

Evgenios Muratidis asteriskteam at digium.com
Tue Apr 13 02:59:00 CDT 2021


Evgenios Muratidis has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15762 )


Change subject: Core/Stasis: Fix "FRACK!, Failed assertion bad magic number" happens when unsubscribe an application from an event source
......................................................................

Core/Stasis: Fix "FRACK!, Failed assertion bad magic number" happens when unsubscribe an application from an event source

Several changes have been made to fix bugs related to applications subscriptions either by technology or by specific resources of the Endpoint's subscriptions

* Fixed a typo in get_subscription when calling ao2_find (needs to pass the Endpoint's Id and not the whole object)
* Fixed return a wrong subscription's object in get_subscription when check fails at search by Endpoint's technology block of code
* In messaging_app_subscribe_endpoint added lines to up the subscription's reference counter in case more than 1 application is subscribed to
* In messaging_app_unsubscribe_endpoint added line to up the subscription's reference counter, at search by Endpoint's resource block of code, cause the below ao2_unlink decreases the subscription's reference counter by 1 and cause follow lines of code decreases it 2 times more, one by calling ao2_ref, and one by auto-calling ao2_cleanup for the subscription's object when the function goes out of scope (through RAII_VAR macro)

ASTERISK-28237 #close
Reported by: Lucas Tardioli Silveira

Change-Id: Ia91b15f8e5ea68f850c66889a6325d9575901729
---
M res/stasis/messaging.c
1 file changed, 13 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/62/15762/1

diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c
index a7716b8..decd230 100644
--- a/res/stasis/messaging.c
+++ b/res/stasis/messaging.c
@@ -385,7 +385,7 @@
 	struct message_subscription *sub = NULL;
 
 	if (endpoint && !ast_strlen_zero(ast_endpoint_get_resource(endpoint))) {
-		sub = ao2_find(endpoint_subscriptions, endpoint, OBJ_SEARCH_KEY);
+		sub = ao2_find(endpoint_subscriptions, ast_endpoint_get_id(endpoint), OBJ_SEARCH_KEY);
 	} else {
 		int i;
 
@@ -397,6 +397,9 @@
 				ao2_bump(sub);
 				break;
 			}
+
+			/* Need to reset the pointer at this line to prevent from wrong using since the above check fails */
+			sub = NULL;
 		}
 		ast_rwlock_unlock(&tech_subscriptions_lock);
 	}
@@ -425,6 +428,10 @@
 	if (AST_VECTOR_SIZE(&sub->applications) == 0) {
 		if (endpoint && !ast_strlen_zero(ast_endpoint_get_resource(endpoint))) {
 			ao2_unlink(endpoint_subscriptions, sub);
+
+			/* Need to up the subscription's reference counter again, cause of the above call decreases it by 1
+			   and cause it will be decreased 2 times at follow lines of code */
+			ao2_bump(sub);
 		} else {
 			ast_rwlock_wrlock(&tech_subscriptions_lock);
 			AST_VECTOR_REMOVE_CMP_UNORDERED(&tech_subscriptions, endpoint ? ast_endpoint_get_id(endpoint) : TECH_WILDCARD,
@@ -495,6 +502,11 @@
 		ao2_unlock(sub);
 		return -1;
 	}
+
+	/* Need up the subscription's reference counter since the subscription has more than 1 application subscribed to */
+	if (AST_VECTOR_SIZE(&sub->applications) > 1) {
+		ao2_bump(sub);
+	}
 	ao2_unlock(sub);
 
 	ast_debug(3, "App '%s' subscribed to messages from endpoint '%s'\n", app_name, endpoint ? ast_endpoint_get_id(endpoint) : "-- ALL --");

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

Gerrit-Project: asterisk
Gerrit-Branch: 16.5
Gerrit-Change-Id: Ia91b15f8e5ea68f850c66889a6325d9575901729
Gerrit-Change-Number: 15762
Gerrit-PatchSet: 1
Gerrit-Owner: Evgenios Muratidis <jone1984 at hotmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210413/5d62048f/attachment.html>


More information about the asterisk-code-review mailing list