Module: kamailio
Branch: 5.0
Commit: 94270b2fe206f324bc60918dbe63f7cc5f7ba6fe
URL:
https://github.com/kamailio/kamailio/commit/94270b2fe206f324bc60918dbe63f7c…
Author: lazedo <luis.azedo(a)factorlusitano.com>
Committer: Luis Azedo <luis(a)2600hz.com>
Date: 2017-05-19T12:36:51+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)
---
Modified: src/modules/registrar/lookup.c
Modified: src/modules/registrar/reply.c
---
Diff:
https://github.com/kamailio/kamailio/commit/94270b2fe206f324bc60918dbe63f7c…
Patch:
https://github.com/kamailio/kamailio/commit/94270b2fe206f324bc60918dbe63f7c…
---
diff --git a/src/modules/registrar/lookup.c b/src/modules/registrar/lookup.c
index c9853a6953..9f99d37e1f 100644
--- a/src/modules/registrar/lookup.c
+++ b/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(®_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(®_xavp_rcd, &xval, NULL);
+ xval.v.xavp = *xavp;
+ if(xavp_add_value(®_xavp_rcd, &xval, NULL)==NULL) {
+ LM_ERR("cannot add ruid xavp to root list\n");
+ xavp_destroy_list(xavp);
+ }
}
return 0;
}
diff --git a/src/modules/registrar/reply.c b/src/modules/registrar/reply.c
index 45568df1d2..c5eb4a3224 100644
--- a/src/modules/registrar/reply.c
+++ b/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(®_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(®_xavp_rcd, &xval, NULL)==NULL) {
LM_ERR("cannot add ruid xavp to root list\n");
- xavp_destroy_list(&xavp);
+ xavp_destroy_list(xavp);
}
}
}