Module: sip-router
Branch: master
Commit: 778c4352f2cbbc572a001e7ef9f2bf18d453a302
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=778c435…
Author: Elena-Ramona Modroiu <ramona(a)rosdev.ro>
Committer: Elena-Ramona Modroiu <ramona(a)rosdev.ro>
Date: Tue Aug 25 11:36:59 2009 +0300
rls: memory leak fix
- port of K #5909
---
modules_k/rls/notify.c | 19 +++++++++++--------
modules_k/rls/resource_notify.c | 34 +++++++++++++++++++---------------
modules_k/rls/subscribe.c | 25 ++++++++++++++++---------
3 files changed, 46 insertions(+), 32 deletions(-)
diff --git a/modules_k/rls/notify.c b/modules_k/rls/notify.c
index eaefad1..9734d6c 100644
--- a/modules_k/rls/notify.c
+++ b/modules_k/rls/notify.c
@@ -216,13 +216,13 @@ int agg_body_sendn_update(str* rl_uri, char* boundary_string, str*
rlmi_body,
cid= generate_cid(rl_uri->s, rl_uri->len);
- len= 2*strlen(boundary_string)+ 4+ 102+ strlen(cid)+ 2+ rlmi_body->len+50;
+ len= 2*strlen(boundary_string)+4+102+strlen(cid)+2+rlmi_body->len+50;
if(multipart_body)
len+= multipart_body->len;
init_len= len;
- body.s= (char*)pkg_malloc(len* sizeof(char));
+ body.s= (char*)pkg_malloc((len+1)* sizeof(char));
if(body.s== NULL)
{
ERR_MEM(PKG_MEM_STR);
@@ -469,6 +469,7 @@ str* constr_multipart_body(db1_res_t* result, char** cid_array,
db_val_t *row_vals;
char* content_id= NULL;
str body= {0, 0};
+ str ctype= {0, 0};
int antet_len;
str* multi_body= NULL;
@@ -489,6 +490,11 @@ str* constr_multipart_body(db1_res_t* result, char** cid_array,
if(row_vals[auth_state_col].val.int_val!= ACTIVE_STATE)
continue;
+ body.s= (char*)row_vals[pres_state_col].val.string_val;
+ body.len= strlen(body.s);
+ ctype.s = (char*)row_vals[content_type_col].val.string_val;
+ ctype.len = strlen(ctype.s);
+
if(length+ antet_len+ body.len+ 4 > size)
{
REALLOC_BUF
@@ -505,13 +511,10 @@ str* constr_multipart_body(db1_res_t* result, char** cid_array,
}
length+= sprintf(buf+ length, "Content-ID: <%s>\r\n",content_id);
- length+= sprintf(buf+ length, "Content-Type: %s\r\n\r\n",
- row_vals[content_type_col].val.string_val);
+ length+= sprintf(buf+ length, "Content-Type: %.*s\r\n\r\n",
+ ctype.len, ctype.s);
- body.s= (char*)row_vals[pres_state_col].val.string_val;
- body.len= strlen(body.s);
-
- length+= sprintf(buf+length,"%s\r\n\r\n", body.s);
+ length+= sprintf(buf+length,"%.*s\r\n\r\n", body.len, body.s);
}
if(length+ strlen( boundary_string)+ 7> size )
diff --git a/modules_k/rls/resource_notify.c b/modules_k/rls/resource_notify.c
index 3afc2d7..ff9a037 100644
--- a/modules_k/rls/resource_notify.c
+++ b/modules_k/rls/resource_notify.c
@@ -406,9 +406,17 @@ done:
goto error;
}
+ pkg_free(res_id->s);
+ pkg_free(res_id);
+
return 1;
error:
+ if(res_id!=NULL)
+ {
+ pkg_free(res_id->s);
+ pkg_free(res_id);
+ }
return -1;
}
/* callid, from_tag, to_tag parameters must be allocated */
@@ -563,11 +571,6 @@ void timer_send_notify(unsigned int ticks,void *param)
goto error;
}
xmlFree(rlmi_cont.s);
- if(buf_len)
- {
- pkg_free(buf);
- buf= NULL;
- }
xmlFreeDoc(rlmi_doc);
rlmi_doc= NULL;
pkg_free(rl_uri);
@@ -576,14 +579,16 @@ void timer_send_notify(unsigned int ticks,void *param)
dialog= NULL;
}
- if(prev_did== NULL || strcmp(prev_did, curr_did)) /*if first or different*/
+ /*if first or different*/
+ if(prev_did==NULL || strcmp(prev_did, curr_did)!=0)
{
/* search the subscription in rlsubs_table*/
if( parse_rlsubs_did(curr_did, &callid, &from_tag, &to_tag)< 0)
{
LM_ERR("bad format for "
"resource list Subscribe dialog indentifier(rlsubs did)\n");
- goto done;
+ prev_did = NULL;
+ continue;
}
hash_code= core_hash(&callid, &to_tag, hash_size);
@@ -598,6 +603,7 @@ void timer_send_notify(unsigned int ticks,void *param)
callid.len, callid.s,from_tag.len,from_tag.s,
to_tag.len,to_tag.s);
lock_release(&rls_table[hash_code].lock);
+ prev_did = NULL;
continue;
}
LM_DBG("Found rl-subs record in hash table\n");
@@ -634,8 +640,10 @@ void timer_send_notify(unsigned int ticks,void *param)
rl_uri[dialog->pres_uri.len]= '\0';
xmlNewProp(list_node, BAD_CAST "uri", BAD_CAST rl_uri);
- xmlNewProp(list_node, BAD_CAST "xmlns", BAD_CAST
"urn:ietf:params:xml:ns:rlmi");
- xmlNewProp(list_node, BAD_CAST "version", BAD_CAST
int2str(dialog->version, &len));
+ xmlNewProp(list_node, BAD_CAST "xmlns",
+ BAD_CAST "urn:ietf:params:xml:ns:rlmi");
+ xmlNewProp(list_node, BAD_CAST "version",
+ BAD_CAST int2str(dialog->version, &len));
xmlNewProp(list_node, BAD_CAST "fullState", BAD_CAST "false");
xmlDocSetRootElement(rlmi_doc, list_node);
@@ -702,7 +710,8 @@ void timer_send_notify(unsigned int ticks,void *param)
REALLOC_BUF
}
buf_len+= sprintf(buf+ buf_len, "--%s\r\n\r\n", bstr.s);
- buf_len+= sprintf(buf+ buf_len, "Content-Transfer-Encoding: binary\r\n");
+ buf_len+= sprintf(buf+ buf_len,
+ "Content-Transfer-Encoding: binary\r\n");
buf_len+= sprintf(buf+ buf_len, "Content-ID: <%s>\r\n", cid);
buf_len+= sprintf(buf+ buf_len, "Content-Type: %s\r\n\r\n",
row_vals[content_type_col].val.string_val);
@@ -750,11 +759,6 @@ void timer_send_notify(unsigned int ticks,void *param)
goto error;
}
xmlFree(rlmi_cont.s);
- if(buf_len)
- {
- pkg_free(buf);
- buf= NULL;
- }
pkg_free(rl_uri);
rl_uri= NULL;
pkg_free(dialog);
diff --git a/modules_k/rls/subscribe.c b/modules_k/rls/subscribe.c
index 7f1c365..bdf311f 100644
--- a/modules_k/rls/subscribe.c
+++ b/modules_k/rls/subscribe.c
@@ -688,6 +688,21 @@ int update_rlsubs( subs_t* subs, unsigned int hash_code)
memcpy(subs->pres_uri.s, s->pres_uri.s, s->pres_uri.len);
subs->pres_uri.len= s->pres_uri.len;
+ if(s->record_route.s!=NULL && s->record_route.len>0)
+ {
+ subs->record_route.s =
+ (char*)pkg_malloc(s->record_route.len* sizeof(char));
+ if(subs->record_route.s==NULL)
+ {
+ ERR_MEM(PKG_MEM_STR);
+ }
+ memcpy(subs->record_route.s, s->record_route.s, s->record_route.len);
+ subs->record_route.len= s->record_route.len;
+ }
+
+ subs->local_cseq= s->local_cseq;
+ subs->version= s->version;
+
if(subs->expires== 0)
{
/* delete record from hash table */
@@ -710,15 +725,7 @@ int update_rlsubs( subs_t* subs, unsigned int hash_code)
ps->next= s->next;
shm_free(s);
}
- else
- {
- s->remote_cseq= subs->remote_cseq;
- s->expires= subs->expires+ (int)time(NULL);
- }
- subs->local_cseq= s->local_cseq;
- subs->version= s->version;
-
lock_release(&rls_table[hash_code].lock);
return 0;
@@ -745,7 +752,7 @@ int resource_subscriptions(subs_t* subs, xmlNodePtr rl_node)
char* uri= NULL;
subs_info_t s;
str wuri= {0, 0};
- static char buf[64];
+ static char buf[256];
str extra_headers;
str did_str= {0, 0};