Przeglądaj źródła

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)
lazedo 8 lat temu
rodzic
commit
94270b2fe2
2 zmienionych plików z 20 dodań i 15 usunięć
  1. 11 7
      src/modules/registrar/lookup.c
  2. 9 8
      src/modules/registrar/reply.c

+ 11 - 7
src/modules/registrar/lookup.c

@@ -99,8 +99,9 @@ int lookup_to_dset(struct sip_msg* _m, udomain_t* _d, str* _uri)
  */
 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};
@@ -111,29 +112,32 @@ int xavp_rcd_helper(ucontact_t* ptr)
 	if(reg_xavp_rcd.s==NULL || reg_xavp_rcd.len<=0) return 0;
 
 	list = xavp_get(&reg_xavp_rcd, NULL);
-	xavp = list;
+	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);
+	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);
+		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);
+	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.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;
 }

+ 9 - 8
src/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};
 	str ename = {"expires", 7};
 	sr_xval_t xval;
@@ -213,7 +214,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;
@@ -336,7 +337,7 @@ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host)
 				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");
 				}
 				/* Add contact expiry */
@@ -344,7 +345,7 @@ int build_contact(sip_msg_t *msg, ucontact_t* c, str *host)
 				xval.type = SR_XTYPE_INT;
 				xval.v.i = (int)(c->expires - act_time);
 
-				if(xavp_add_value(&ename, &xval, &xavp)==NULL) {
+				if(xavp_add_value(&ename, &xval, xavp)==NULL) {
 					LM_ERR("cannot add expires value to xavp\n");
 				}
 			}
@@ -354,16 +355,16 @@ 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);
 			}
 		}
 	}