Module: sip-router
Branch: 3.1
Commit: 09eae6628bcdc060db79af875e8b912460bf5f2e
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=09eae66…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Feb 3 23:54:13 2011 +0100
presence(k): avoid str* alloc for local contact
- it is not used further an leads to memleak
(cherry picked from commit 4462757813b146e2ca4018b1a93636115e2408f6)
---
modules_k/presence/subscribe.c | 7 ++-----
modules_k/presence/utils_func.h | 37 +++++++++++++------------------------
2 files changed, 15 insertions(+), 29 deletions(-)
diff --git a/modules_k/presence/subscribe.c b/modules_k/presence/subscribe.c
index 94bf9d8..23030a3 100644
--- a/modules_k/presence/subscribe.c
+++ b/modules_k/presence/subscribe.c
@@ -755,7 +755,6 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp,
{
str rec_route= {0, 0};
int rt = 0;
- str* contact= NULL;
contact_body_t *b;
struct to_body *pto, *pfrom = NULL, TO;
int lexpire;
@@ -962,13 +961,11 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int
mexp,
if((!scontact.s) || (scontact.len== 0))
{
- contact= get_local_contact(msg);
- if(contact== NULL)
+ if(ps_fill_local_contact(msg, &subs->local_contact)<0)
{
- LM_ERR("in function get_local_contact\n");
+ LM_ERR("cannot get local contact address\n");
goto error;
}
- subs->local_contact= *contact;
}
else
subs->local_contact= scontact;
diff --git a/modules_k/presence/utils_func.h b/modules_k/presence/utils_func.h
index 077fef1..16e427d 100644
--- a/modules_k/presence/utils_func.h
+++ b/modules_k/presence/utils_func.h
@@ -85,27 +85,19 @@ static inline int uandd_to_uri(str user, str domain, str *out)
return 0;
}
-static inline str* get_local_contact(struct sip_msg* msg)
+static inline int ps_fill_local_contact(struct sip_msg* msg, str *contact)
{
str ip;
char* proto;
int port;
int len;
- str* contact;
int plen;
- contact= (str*)pkg_malloc(sizeof(str));
- if(contact== NULL)
- {
- LM_ERR("No more memory\n");
- return NULL;
- }
contact->s= (char*)pkg_malloc(LCONTACT_BUF_SIZE);
if(contact->s== NULL)
{
LM_ERR("No more memory\n");
- pkg_free(contact);
- return NULL;
+ goto error;
}
memset(contact->s, 0, LCONTACT_BUF_SIZE);
@@ -128,18 +120,14 @@ static inline str* get_local_contact(struct sip_msg* msg)
else
{
LM_ERR("unsupported proto\n");
- pkg_free(contact->s);
- pkg_free(contact);
- return NULL;
+ goto error;
}
ip.s= ip_addr2a(&msg->rcv.dst_ip);
if(ip.s== NULL)
{
LM_ERR("transforming ip_addr to ascii\n");
- pkg_free(contact->s);
- pkg_free(contact);
- return NULL;
+ goto error;
}
ip.len= strlen(ip.s);
port = msg->rcv.dst_port;
@@ -154,25 +142,26 @@ static inline str* get_local_contact(struct sip_msg* msg)
if(contact->len> LCONTACT_BUF_SIZE - 21)
{
LM_ERR("buffer overflow\n");
- pkg_free(contact->s);
- pkg_free(contact);
- return NULL;
+ goto error;
}
len= sprintf(contact->s+contact->len, ":%d;transport=" , port);
if(len< 0)
{
LM_ERR("unsuccessful sprintf\n");
- pkg_free(contact->s);
- pkg_free(contact);
- return NULL;
+ goto error;
}
contact->len+= len;
strncpy(contact->s+ contact->len, proto, plen);
contact->len += plen;
- return contact;
-
+ return 0;
+error:
+ if(contact->s!=NULL)
+ pkg_free(contact->s);
+ contact->s = 0;
+ contact->len = 0;
+ return -1;
}
//str* int_to_str(long int n);