Module: kamailio
Branch: master
Commit: bb3840161acd3b2dbe41001ebfb2bd779bfd68d0
URL:
https://github.com/kamailio/kamailio/commit/bb3840161acd3b2dbe41001ebfb2bd7…
Author: lazedo <luis.azedo(a)factorlusitano.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-05-16T16:56:07+02:00
registrar: proper linking of xavps in the xavp_rcd
- avoid leaking of shm when using save() in async operations
- part of PR #1111
---
Modified: src/modules/registrar/lookup.c
Modified: src/modules/registrar/reply.c
---
Diff:
https://github.com/kamailio/kamailio/commit/bb3840161acd3b2dbe41001ebfb2bd7…
Patch:
https://github.com/kamailio/kamailio/commit/bb3840161acd3b2dbe41001ebfb2bd7…
---
diff --git a/src/modules/registrar/lookup.c b/src/modules/registrar/lookup.c
index cd261b1..bff0e0e 100644
--- a/src/modules/registrar/lookup.c
+++ b/src/modules/registrar/lookup.c
@@ -105,8 +105,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};
@@ -117,29 +118,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 45568df..c5eb4a3 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);
}
}
}