[sr-dev] git:4.4:9e343f35: registrar: proper linking of xavps in the xavp_rcd

Luis Azedo luis at 2600hz.com
Fri May 19 13:46:23 CEST 2017


Module: kamailio
Branch: 4.4
Commit: 9e343f3585a148f9a117195f179723e74bc475e8
URL: https://github.com/kamailio/kamailio/commit/9e343f3585a148f9a117195f179723e74bc475e8

Author: lazedo <luis.azedo at factorlusitano.com>
Committer: Luis Azedo <luis at 2600hz.com>
Date: 2017-05-19T12:45:17+01:00

registrar: proper linking of xavps in the xavp_rcd

- avoid leaking of shm when using save() in async operations
- part of PR #1111

(cherry picked from commit bb3840161acd3b2dbe41001ebfb2bd779bfd68d0)

Conflicts:
	modules/registrar/lookup.c
	modules/registrar/reply.c

---

Modified: modules/registrar/lookup.c
Modified: modules/registrar/reply.c

---

Diff:  https://github.com/kamailio/kamailio/commit/9e343f3585a148f9a117195f179723e74bc475e8.diff
Patch: https://github.com/kamailio/kamailio/commit/9e343f3585a148f9a117195f179723e74bc475e8.patch

---

diff --git a/modules/registrar/lookup.c b/modules/registrar/lookup.c
index 50da15d622..62c0bf86a6 100644
--- a/modules/registrar/lookup.c
+++ b/modules/registrar/lookup.c
@@ -96,8 +96,9 @@ int lookup_to_dset(struct sip_msg* _m, udomain_t* _d, str* _uri) {
  * add xavp with details of the record (ruid, ...)
  */
 int xavp_rcd_helper(ucontact_t* ptr) {
-	sr_xavp_t *xavp=NULL;
+	sr_xavp_t **xavp=NULL;
 	sr_xavp_t *list=NULL;
+	sr_xavp_t *new_xavp=NULL;
 	str xname_ruid = {"ruid", 4};
 	str xname_received = { "received", 8};
 	str xname_contact = { "contact", 7};
@@ -105,34 +106,34 @@ int xavp_rcd_helper(ucontact_t* ptr) {
 
 	if(ptr==NULL) return -1;
 
-	if(reg_xavp_rcd.s!=NULL)
-	{
-		list = xavp_get(&reg_xavp_rcd, NULL);
-		xavp = list;
-		memset(&xval, 0, sizeof(sr_xval_t));
-		xval.type = SR_XTYPE_STR;
-		xval.v.s = ptr->ruid;
-		xavp_add_value(&xname_ruid, &xval, &xavp);
-
-		if(ptr->received.len > 0)
-		{
-			memset(&xval, 0, sizeof(sr_xval_t));
-			xval.type = SR_XTYPE_STR;
-			xval.v.s = ptr->received;
-			xavp_add_value(&xname_received, &xval, &xavp);
-		}
+	if(reg_xavp_rcd.s==NULL || reg_xavp_rcd.len<=0) return 0;
+
+	list = xavp_get(&reg_xavp_rcd, NULL);
+	xavp = list ? &list->val.v.xavp : &new_xavp;
+	memset(&xval, 0, sizeof(sr_xval_t));
+	xval.type = SR_XTYPE_STR;
+	xval.v.s = ptr->ruid;
+	xavp_add_value(&xname_ruid, &xval, xavp);
 
+	if(ptr->received.len > 0) {
 		memset(&xval, 0, sizeof(sr_xval_t));
 		xval.type = SR_XTYPE_STR;
-		xval.v.s = ptr->c;
-		xavp_add_value(&xname_contact, &xval, &xavp);
-
-		if(list==NULL)
-		{
-			/* no reg_xavp_rcd xavp in root list - add it */
-			xval.type = SR_XTYPE_XAVP;
-			xval.v.xavp = xavp;
-			xavp_add_value(&reg_xavp_rcd, &xval, NULL);
+		xval.v.s = ptr->received;
+		xavp_add_value(&xname_received, &xval, xavp);
+	}
+
+	memset(&xval, 0, sizeof(sr_xval_t));
+	xval.type = SR_XTYPE_STR;
+	xval.v.s = ptr->c;
+	xavp_add_value(&xname_contact, &xval, xavp);
+
+	if(list==NULL) {
+		/* no reg_xavp_rcd xavp in root list - add it */
+		xval.type = SR_XTYPE_XAVP;
+		xval.v.xavp = *xavp;
+		if(xavp_add_value(&reg_xavp_rcd, &xval, NULL)==NULL) {
+			LM_ERR("cannot add ruid xavp to root list\n");
+			xavp_destroy_list(xavp);
 		}
 	}
 	return 0;
diff --git a/modules/registrar/reply.c b/modules/registrar/reply.c
index 27cc6f3bca..884012b443 100644
--- a/modules/registrar/reply.c
+++ b/modules/registrar/reply.c
@@ -173,8 +173,9 @@ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host)
 	unsigned int ahash;
 	unsigned short digit;
 	int mode;
-	sr_xavp_t *xavp=NULL;
+	sr_xavp_t **xavp=NULL;
 	sr_xavp_t *list=NULL;
+	sr_xavp_t *new_xavp=NULL;
 	str xname = {"ruid", 4};
 	sr_xval_t xval;
 
@@ -212,7 +213,7 @@ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host)
 	if(reg_xavp_rcd.s!=NULL)
 	{
 		list = xavp_get(&reg_xavp_rcd, NULL);
-		xavp = list;
+		xavp = list ? &list->val.v.xavp : &new_xavp;
 	}
 
 	fl = 0;
@@ -334,7 +335,7 @@ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host)
 				memset(&xval, 0, sizeof(sr_xval_t));
 				xval.type = SR_XTYPE_STR;
 				xval.v.s = c->ruid;
-				if(xavp_add_value(&xname, &xval, &xavp)==NULL) {
+				if(xavp_add_value(&xname, &xval, xavp)==NULL) {
 					LM_ERR("cannot add ruid value to xavp\n");
 				}
 			}
@@ -346,14 +347,13 @@ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host)
 	/* add xavp with details of the record (ruid, ...) */
 	if(reg_xavp_rcd.s!=NULL)
 	{
-		if(list==NULL && xavp!=NULL)
+		if(list==NULL && *xavp!=NULL)
 		{
-			/* no reg_xavp_rcd xavp in root list - add it */
 			xval.type = SR_XTYPE_XAVP;
-			xval.v.xavp = xavp;
+			xval.v.xavp = *xavp;
 			if(xavp_add_value(&reg_xavp_rcd, &xval, NULL)==NULL) {
 				LM_ERR("cannot add ruid xavp to root list\n");
-				xavp_destroy_list(&xavp);
+				xavp_destroy_list(xavp);
 			}
 		}
 	}




More information about the sr-dev mailing list