[Asterisk-code-review] res pjsip/pjsip distributor.c: Pull some assignments out of ... (asterisk[15])

Richard Mudgett asteriskteam at digium.com
Tue May 1 17:17:10 CDT 2018


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/8891


Change subject: res_pjsip/pjsip_distributor.c: Pull some assignments out of if tests.
......................................................................

res_pjsip/pjsip_distributor.c: Pull some assignments out of if tests.

Change-Id: I3d30d638b53a4bbe9bf9aad853c649d583894112
---
M res/res_pjsip/pjsip_distributor.c
1 file changed, 16 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/91/8891/1

diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c
index 7f512d1..a0d0bdb 100644
--- a/res/res_pjsip/pjsip_distributor.c
+++ b/res/res_pjsip/pjsip_distributor.c
@@ -690,7 +690,8 @@
 		 * the find without OBJ_UNLINK to prevent the unnecessary write lock, then unlink
 		 * if needed.
 		 */
-		if ((unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY))) {
+		unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
+		if (unid) {
 			ao2_unlink(unidentified_requests, unid);
 			ao2_ref(unid, -1);
 		}
@@ -699,14 +700,14 @@
 
 	endpoint = ast_sip_identify_endpoint(rdata);
 	if (endpoint) {
-		if ((unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY))) {
+		unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
+		if (unid) {
 			ao2_unlink(unidentified_requests, unid);
 			ao2_ref(unid, -1);
 		}
 	}
 
 	if (!endpoint) {
-
 		/* always use an artificial endpoint - per discussion no reason
 		   to have "alwaysauthreject" as an option.  It is felt using it
 		   was a bug fix and it is not needed since we are not worried about
@@ -715,9 +716,10 @@
 		endpoint = ast_sip_get_artificial_endpoint();
 	}
 
+	/* endpoint ref held by mod_data[] */
 	rdata->endpt_info.mod_data[endpoint_mod.id] = endpoint;
 
-	if ((endpoint == artificial_endpoint) && !is_ack) {
+	if (endpoint == artificial_endpoint && !is_ack) {
 		char name[AST_UUID_STR_LEN] = "";
 		pjsip_uri *from = rdata->msg_info.from->uri;
 
@@ -726,17 +728,20 @@
 			ast_copy_pj_str(name, &sip_from->user, sizeof(name));
 		}
 
-		if ((unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY))) {
+		unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
+		if (unid) {
 			check_endpoint(rdata, unid, name);
 			ao2_ref(unid, -1);
 		} else if (using_auth_username) {
 			ao2_wrlock(unidentified_requests);
-			/* The check again with the write lock held allows us to eliminate the DUPS_REPLACE and sort_fn */
-			if ((unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY | OBJ_NOLOCK))) {
+			/* Checking again with the write lock held allows us to eliminate the DUPS_REPLACE and sort_fn */
+			unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name,
+				OBJ_SEARCH_KEY | OBJ_NOLOCK);
+			if (unid) {
 				check_endpoint(rdata, unid, name);
 			} else {
-				unid = ao2_alloc_options(sizeof(*unid) + strlen(rdata->pkt_info.src_name) + 1, NULL,
-					AO2_ALLOC_OPT_LOCK_RWLOCK);
+				unid = ao2_alloc_options(sizeof(*unid) + strlen(rdata->pkt_info.src_name) + 1,
+					NULL, AO2_ALLOC_OPT_LOCK_RWLOCK);
 				if (!unid) {
 					ao2_unlock(unidentified_requests);
 					return PJ_TRUE;
@@ -860,7 +865,8 @@
 			return PJ_TRUE;
 		case AST_SIP_AUTHENTICATION_SUCCESS:
 			/* See note in endpoint_lookup about not holding an unnecessary write lock */
-			if ((unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY))) {
+			unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
+			if (unid) {
 				ao2_unlink(unidentified_requests, unid);
 				ao2_ref(unid, -1);
 			}

-- 
To view, visit https://gerrit.asterisk.org/8891
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d30d638b53a4bbe9bf9aad853c649d583894112
Gerrit-Change-Number: 8891
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180501/e23163d2/attachment.html>


More information about the asterisk-code-review mailing list