[asterisk-commits] kharwell: branch mjordan/pjsip-cli r404455 - in /team/mjordan/pjsip-cli/res: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 20 15:04:24 CST 2013


Author: kharwell
Date: Fri Dec 20 15:04:22 2013
New Revision: 404455

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404455
Log:
pjsip cli: pjsip list contacts crashes

Fixed crash when issuing a "pjsip list contacts" cli command.  Also fixed a
couple of other places where there were memory leaks and containers being
unreffed before they needed to be.

(closes issue ASTERISK-23050)
Reported by: Rusty Newton

Modified:
    team/mjordan/pjsip-cli/res/res_pjsip/location.c
    team/mjordan/pjsip-cli/res/res_pjsip_endpoint_identifier_ip.c

Modified: team/mjordan/pjsip-cli/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/pjsip-cli/res/res_pjsip/location.c?view=diff&rev=404455&r1=404454&r2=404455
==============================================================================
--- team/mjordan/pjsip-cli/res/res_pjsip/location.c (original)
+++ team/mjordan/pjsip-cli/res/res_pjsip/location.c Fri Dec 20 15:04:22 2013
@@ -285,6 +285,32 @@
 	return 0;
 }
 
+static void destroy_contact_pair(void *obj)
+{
+	struct ast_sip_aor_contact_pair *pair = obj;
+	ao2_cleanup(pair->aor);
+	ao2_cleanup(pair->contact);
+}
+
+static struct ast_sip_aor_contact_pair *create_contact_pair(
+	struct ast_sip_aor *aor, struct ast_sip_contact *contact)
+{
+	struct ast_sip_aor_contact_pair *pair = ao2_alloc(
+		sizeof(*pair), destroy_contact_pair);
+
+	if (!pair) {
+		return NULL;
+	}
+
+	pair->aor = aor;
+	pair->contact = contact;
+
+	ao2_ref(pair->aor, +1);
+	ao2_ref(pair->contact, +1);
+
+	return pair;
+}
+
 int ast_sip_for_each_contact(struct ast_sip_aor *aor,
 		ao2_callback_fn on_contact, void *arg)
 {
@@ -300,16 +326,10 @@
 	i = ao2_iterator_init(contacts, 0);
 	while ((contact = ao2_iterator_next(&i))) {
 		int res;
-		RAII_VAR(struct ast_sip_aor_contact_pair *, acp, NULL, ao2_cleanup);
-		acp = ao2_alloc(sizeof(struct ast_sip_aor_contact_pair), NULL);
-		ao2_ref(aor, +1);
-		ao2_ref(acp, +1);
-		acp->aor = aor;
-		acp->contact = contact;
-		res = on_contact(acp, arg, 0);
-		ao2_ref(contact, -1);
-		ao2_ref(aor, -1);
-		if (res) {
+		RAII_VAR(struct ast_sip_aor_contact_pair *,
+			 acp, create_contact_pair(aor, contact), ao2_cleanup);
+
+		if (!acp || (res = on_contact(acp, arg, 0))) {
 			ao2_iterator_destroy(&i);
 			return -1;
 		}
@@ -379,14 +399,16 @@
 	.format_ami = format_ami_endpoint_aor
 };
 
-static int populate_contact_container(void *obj, void *arg, int flags) {
+static int populate_contact_container(void *obj, void *arg, int flags)
+{
 	struct ast_sip_aor_contact_pair *acp = obj;
 	struct ao2_container *container = arg;
 	ao2_link_flags(container, acp, OBJ_NOLOCK);
 	return 0;
 }
 
-static int gather_aor_channels(void *obj, void *arg, int flags) {
+static int gather_aor_channels(void *obj, void *arg, int flags)
+{
 	struct ast_sip_aor *aor = obj;
 	struct ao2_container *container = arg;
 	ast_sip_for_each_contact(aor, populate_contact_container, container);
@@ -510,7 +532,8 @@
 	return 0;
 }
 
-static int cli_print_aor_body(void *obj, void *arg, int flags) {
+static int cli_print_aor_body(void *obj, void *arg, int flags)
+{
 	struct ast_sip_aor *aor = obj;
 	struct ast_sip_cli_context *context = arg;
 	struct ast_sip_cli_formatter_entry *formatter_entry;

Modified: team/mjordan/pjsip-cli/res/res_pjsip_endpoint_identifier_ip.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/pjsip-cli/res/res_pjsip_endpoint_identifier_ip.c?view=diff&rev=404455&r1=404454&r2=404455
==============================================================================
--- team/mjordan/pjsip-cli/res/res_pjsip_endpoint_identifier_ip.c (original)
+++ team/mjordan/pjsip-cli/res/res_pjsip_endpoint_identifier_ip.c Fri Dec 20 15:04:22 2013
@@ -255,6 +255,7 @@
 
 static int unload_module(void)
 {
+	ast_sip_unregister_endpoint_formatter(&endpoint_identify_formatter);
 	ast_sip_unregister_endpoint_identifier(&ip_identifier);
 	return 0;
 }




More information about the asterisk-commits mailing list