Module: sip-router
Branch: master
Commit: 1d6b1d8765d7a6d21c291d2076a3a80a1710c11c
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1d6b1d8…
Author: Jason Penton <jason.penton(a)gmail.com>
Committer: Jason Penton <jason.penton(a)gmail.com>
Date: Fri Feb 14 09:57:45 2014 +0200
lib/ims:modules/ims_charging,ims_icscf,ims_qos,ims_registrar_scscf: fixed pkg_mem leak
- fixed leak when parsing msg headers on a shm msg
- instead now pass in flag to say if parsing is on shm_msg or not (is_shm)
- assumes all common headers are already parsed before pkg_mem msg is cloned
---
lib/ims/ims_getters.c | 33 ++++++++++++++++++-----
lib/ims/ims_getters.h | 3 +-
modules/ims_charging/ims_ro.c | 4 +-
modules/ims_icscf/location.c | 2 +-
modules/ims_qos/rx_aar.c | 13 +++++++--
modules/ims_registrar_scscf/registrar_notify.c | 4 +-
modules/ims_registrar_scscf/save.c | 2 +-
7 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/lib/ims/ims_getters.c b/lib/ims/ims_getters.c
index 082a5c2..aa37c7d 100644
--- a/lib/ims/ims_getters.c
+++ b/lib/ims/ims_getters.c
@@ -388,13 +388,32 @@ str s_asserted_identity={"P-Asserted-Identity",19};
* @param msg - the sip message
* @returns the asserted identity
*/
-str cscf_get_asserted_identity(struct sip_msg *msg)
-{
- str uri = {0,0};
- if (!msg) return uri;
- if((parse_pai_header(msg) == 0) && (msg->pai) &&
(msg->pai->parsed)) {
+str cscf_get_asserted_identity(struct sip_msg *msg, int is_shm) {
+ int len;
+ str uri = { 0, 0 };
+
+ if (!msg || !msg->pai)
+ return uri;
+
+ if ((parse_pai_header(msg) == 0) && (msg->pai) &&
(msg->pai->parsed)) {
to_body_t *pai = get_pai(msg)->id;
- return pai->uri;
+ if (!is_shm)
+ return pai->uri;
+
+ //make a pkg malloc str to return to consuming function
+ len = pai->uri.len + 1;
+ uri.s = (char*) pkg_malloc(pai->uri.len + 1);
+ if (!uri.s) {
+ LM_ERR("no more pkg mem\n");
+ return uri;
+ }
+ memset(uri.s, 0, len);
+ memcpy(uri.s, pai->uri.s, pai->uri.len);
+ uri.len = pai->uri.len;
+
+ p_id_body_t* ptr = (p_id_body_t*) msg->pai->parsed;
+ msg->pai->parsed = 0;
+ free_pai_ppi_body(ptr);
}
return uri;
}
@@ -855,7 +874,7 @@ int cscf_is_initial_request(struct sip_msg *msg)
int cscf_get_originating_user( struct sip_msg * msg, str *uri )
{
struct to_body * from;
- *uri = cscf_get_asserted_identity(msg);
+ *uri = cscf_get_asserted_identity(msg, 0);
if (!uri->len) {
/* Fallback to From header */
if ( parse_from_header( msg ) == -1 ) {
diff --git a/lib/ims/ims_getters.h b/lib/ims/ims_getters.h
index 0b01ffc..2217ddc 100644
--- a/lib/ims/ims_getters.h
+++ b/lib/ims/ims_getters.h
@@ -153,9 +153,10 @@ int cscf_has_originating(struct sip_msg *msg, char *str1, char
*str2);
/**
* Looks for the P-Asserted-Identity header and extracts its content
* @param msg - the sip message
+ * @is_shm - is the message a shm message
* @returns the asserted identity
*/
-str cscf_get_asserted_identity(struct sip_msg *msg);
+str cscf_get_asserted_identity(struct sip_msg *msg, int is_shm);
/**
* Extracts the realm from a SIP/TEL URI.
* - SIP - the hostname
diff --git a/modules/ims_charging/ims_ro.c b/modules/ims_charging/ims_ro.c
index f650e90..ab5937a 100644
--- a/modules/ims_charging/ims_ro.c
+++ b/modules/ims_charging/ims_ro.c
@@ -361,7 +361,7 @@ int get_sip_header_info(struct sip_msg * req,
*expires = cscf_get_expires_hdr(req, 0);
*callid = cscf_get_call_id(req, NULL);
- if ((*asserted_id_uri = cscf_get_asserted_identity(req)).len == 0) {
+ if ((*asserted_id_uri = cscf_get_asserted_identity(req, 0)).len == 0) {
LM_DBG("No P-Asserted-Identity hdr found. Using From hdr");
if (!cscf_get_from_uri(req, asserted_id_uri)) {
@@ -955,7 +955,7 @@ int Ro_Send_CCR(struct sip_msg *msg, str* direction, str* charge_type,
str* unit
//getting asserted identity
- if ((asserted_identity = cscf_get_asserted_identity(msg)).len == 0) {
+ if ((asserted_identity = cscf_get_asserted_identity(msg, 0)).len == 0) {
LM_DBG("No P-Asserted-Identity hdr found. Using From hdr for
asserted_identity");
asserted_identity = dlg->from_uri;
}
diff --git a/modules/ims_icscf/location.c b/modules/ims_icscf/location.c
index 3d0f09a..4aac051 100644
--- a/modules/ims_icscf/location.c
+++ b/modules/ims_icscf/location.c
@@ -98,7 +98,7 @@ int I_perform_location_information_request(struct sip_msg* msg, char*
route, cha
/* extract data from message */
if (orig) {
- public_identity = cscf_get_asserted_identity(msg);
+ public_identity = cscf_get_asserted_identity(msg, 0);
} else {
public_identity = cscf_get_public_identity_from_requri(msg);
}
diff --git a/modules/ims_qos/rx_aar.c b/modules/ims_qos/rx_aar.c
index 69d04c0..3d7fc22 100644
--- a/modules/ims_qos/rx_aar.c
+++ b/modules/ims_qos/rx_aar.c
@@ -411,7 +411,7 @@ int rx_send_aar(struct sip_msg *req, struct sip_msg *res,
AAASession* auth, char* direction, saved_transaction_t* saved_t_data) {
AAAMessage* aar = 0;
-
+ int must_free_asserted_identity = 0;
str identifier;
int identifier_type;
@@ -494,17 +494,20 @@ int rx_send_aar(struct sip_msg *req, struct sip_msg *res,
if (dlg_direction == DLG_MOBILE_ORIGINATING) {
LM_DBG("originating direction\n");
- if ((identifier = cscf_get_asserted_identity(req)).len == 0) {
+ if ((identifier = cscf_get_asserted_identity(req, 1)).len == 0) {
LM_DBG("No P-Asserted-Identity hdr found in request. Using From hdr in
req");
if (!cscf_get_from_uri(req, &identifier)) {
LM_ERR("Error assigning P-Asserted-Identity using From hdr in req");
goto error;
}
+ } else {
+ must_free_asserted_identity = 1;
}
} else {
LM_DBG("terminating direction\n");
- if ((identifier = cscf_get_asserted_identity(res)).len == 0) {
+
+ if ((identifier = cscf_get_asserted_identity(res, 0)).len == 0) {
LM_DBG("No P-Asserted-Identity hdr found in response. Using To hdr in
resp");
if (!cscf_get_to_uri(res, &identifier)) {
@@ -522,6 +525,10 @@ int rx_send_aar(struct sip_msg *req, struct sip_msg *res,
rx_add_subscription_id_avp(aar, identifier, identifier_type);
+ if (must_free_asserted_identity) {
+ pkg_free(identifier.s);
+ }
+
LM_DBG("Adding reservation priority...\n");
/* Add Reservation Priority AVP*/
diff --git a/modules/ims_registrar_scscf/registrar_notify.c
b/modules/ims_registrar_scscf/registrar_notify.c
index 1fc1f07..3f04dbe 100644
--- a/modules/ims_registrar_scscf/registrar_notify.c
+++ b/modules/ims_registrar_scscf/registrar_notify.c
@@ -153,7 +153,7 @@ int can_publish_reg(struct sip_msg *msg, char *_t, char *str2) {
goto done;
}
- asserted_id = cscf_get_asserted_identity(msg);
+ asserted_id = cscf_get_asserted_identity(msg, 0);
if (!asserted_id.len) {
LM_ERR("P-Asserted-Identity empty.\n");
goto error;
@@ -312,7 +312,7 @@ int can_subscribe_to_reg(struct sip_msg *msg, char *_t, char *str2) {
}
- asserted_id = cscf_get_asserted_identity(msg);
+ asserted_id = cscf_get_asserted_identity(msg, 0);
if (!asserted_id.len) {
LM_ERR("P-Asserted-Identity empty.\n");
goto error;
diff --git a/modules/ims_registrar_scscf/save.c b/modules/ims_registrar_scscf/save.c
index a54728c..78d5793 100644
--- a/modules/ims_registrar_scscf/save.c
+++ b/modules/ims_registrar_scscf/save.c
@@ -987,7 +987,7 @@ int assign_server_unreg(struct sip_msg* _m, char* str1, str*
direction, char* ro
enum cscf_dialog_direction dir = cscf_get_dialog_direction(direction->s);
switch (dir) {
case CSCF_MOBILE_ORIGINATING:
- public_identity = cscf_get_asserted_identity(_m);
+ public_identity = cscf_get_asserted_identity(_m, 0);
break;
case CSCF_MOBILE_TERMINATING:
public_identity = cscf_get_public_identity_from_requri(_m);