Browse Source

pv/presence/pua: add a couple of missing free_to_params

- patch by Walter Doekes, closes FS#156
Daniel-Constantin Mierla 14 years ago
parent
commit
d3b4e5486e

+ 4 - 4
modules_k/presence/subscribe.c

@@ -922,7 +922,7 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp,
 	str rec_route= {0, 0};
 	int rt  = 0;
 	contact_body_t *b;
-	struct to_body *pto, *pfrom = NULL, TO;
+	struct to_body *pto, TO = {0}, *pfrom = NULL;
 	int lexpire;
 	str rtag_value;
 	struct sip_uri uri;
@@ -962,7 +962,6 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp,
 	}
 	else
 	{
-		memset( &TO , 0, sizeof(TO) );
 		parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
 		if( TO.uri.len <= 0 )
 		{
@@ -1135,11 +1134,12 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp,
 	}
 	else
 		subs->local_contact= scontact;
-	
+
+	free_to_params(&TO);
 	return 0;
 	
 error:
-
+	free_to_params(&TO);
 	return -1;
 }
 

+ 10 - 7
modules_k/pua/hash.c

@@ -446,7 +446,7 @@ int update_contact(struct sip_msg* msg, char* str1, char* str2)
 {
 	ua_pres_t* p, hentity;
 	str contact;
-	struct to_body *pto= NULL, TO, *pfrom = NULL;
+	struct to_body *pto = NULL, TO = {0}, *pfrom = NULL;
 	unsigned int hash_code;
 
 	if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
@@ -497,20 +497,19 @@ int update_contact(struct sip_msg* msg, char* str1, char* str2)
 	}
 	else
 	{
-		memset( &TO , 0, sizeof(TO) );
 		parse_to(msg->to->body.s,msg->to->body.s +
 			msg->to->body.len + 1, &TO);
 		if(TO.uri.len <= 0) 
 		{
 			LM_DBG("'To' header NOT parsed\n");
-			return -1;
+			goto error;
 		}
 		pto = &TO;
 	}			
 	if( pto->tag_value.s ==NULL || pto->tag_value.len == 0)
 	{
 		LM_ERR("no from tag value present\n");
-		return -1;
+		goto error;
 	}
 	hentity.watcher_uri= &pto->uri;
 	hentity.pres_uri= &pfrom->uri; 
@@ -525,7 +524,7 @@ int update_contact(struct sip_msg* msg, char* str1, char* str2)
 	if(msg->contact== NULL || msg->contact->body.s== NULL)
 	{
 		LM_ERR("no contact header found in 200 OK reply");
-		return -1;
+		goto error;
 	}
 	contact= msg->contact->body;
 
@@ -536,7 +535,7 @@ int update_contact(struct sip_msg* msg, char* str1, char* str2)
 	{
 		lock_release(&HashT->p_records[hash_code].lock);
 		LM_ERR("no record for the dialog found in hash table\n");
-		return -1;
+		goto error;
 	}
 
 	shm_free(p->remote_contact.s);
@@ -551,7 +550,7 @@ int update_contact(struct sip_msg* msg, char* str1, char* str2)
 		{
 			LM_ERR("no more shared memory\n");
 			lock_release(&HashT->p_records[hash_code].lock);
-			return -1;
+			goto error;
 		}
 		memcpy(p->remote_contact.s, contact.s, contact.len);
 		p->remote_contact.len= contact.len;
@@ -559,7 +558,11 @@ int update_contact(struct sip_msg* msg, char* str1, char* str2)
 
 	lock_release(&HashT->p_records[hash_code].lock);
 
+	free_to_params(&TO);
 	return 1;
 
+error:
+	free_to_params(&TO);
+	return -1;
 }
 

+ 3 - 3
modules_k/pua/send_subscribe.c

@@ -216,7 +216,7 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps)
 	int lexpire= 0;
 	unsigned int cseq;
 	ua_pres_t* presentity= NULL, *hentity= NULL;
-	struct to_body *pto= NULL, *pfrom = NULL, TO;
+	struct to_body *pto = NULL, TO = {0}, *pfrom = NULL;
 	int size= 0;
 	unsigned int hash_code;
 	int flag ;
@@ -326,7 +326,6 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps)
 		}
 		else
 		{
-			memset( &TO , 0, sizeof(TO) );
 			parse_to(msg->to->body.s,msg->to->body.s +
 				msg->to->body.len + 1, &TO);
 			if(TO.uri.len <= 0) 
@@ -618,8 +617,9 @@ error:
 		shm_free(hentity);
 		hentity= NULL;
 	}
-	return;
 
+	free_to_params(&TO);
+	return;
 }
 
 ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag)

+ 5 - 8
modules_k/pua_bla/notify.c

@@ -39,7 +39,7 @@
 int bla_handle_notify(struct sip_msg* msg, char* s1, char* s2)
 {
  	publ_info_t publ;
- 	struct to_body *pto= NULL, TO, *pfrom = NULL;
+	struct to_body *pto = NULL, TO = {0}, *pfrom = NULL;
  	str body;
  	ua_pres_t dialog;
  	unsigned int expires= 0;
@@ -48,7 +48,6 @@ int bla_handle_notify(struct sip_msg* msg, char* s1, char* s2)
 	int found= 0;
  	str extra_headers= {0, 0};
  	static char buf[255];
- 	xmlDoc* doc= NULL;
 	str contact;
 
 	memset(&publ, 0, sizeof(publ_info_t));
@@ -76,7 +75,6 @@ int bla_handle_notify(struct sip_msg* msg, char* s1, char* s2)
   	}
  	else
   	{
-  		memset( &TO , 0, sizeof(TO) );
   		parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
   		if(TO.uri.len <= 0)
   		{
@@ -245,13 +243,12 @@ int bla_handle_notify(struct sip_msg* msg, char* s1, char* s2)
       
    	xmlCleanupParser();
    	xmlMemoryDump();
-   
-  	return 1;
+
+	free_to_params(&TO);
+	return 1;
    
 error:
-   	if(doc)
-   		xmlFreeDoc(doc);
-   
+	free_to_params(&TO);
    	return 0;
 }
 

+ 11 - 10
modules_k/pua_xmpp/simple2xmpp.c

@@ -51,13 +51,12 @@ int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id, int is_te
 
 int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 {
-	struct to_body *pto, TO, *pfrom= NULL;
+	struct to_body *pto, TO = {0}, *pfrom = NULL;
 	str to_uri;
 	char* uri= NULL;
 	str from_uri;
 	struct hdr_field* hdr= NULL;
 	str body;
-	xmlDocPtr doc= NULL;
 	int is_terminated= 0;
 	str id;
 	ua_pres_t dialog;
@@ -91,12 +90,11 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 	}
 	else
 	{
-		memset( &TO , 0, sizeof(TO) );
 		parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
 		if(TO.uri.len <= 0) 
 		{
 			LM_ERR("'To' header NOT parsed\n");
-			return -1;
+			goto error;
 		}
 		pto = &TO;
 	}
@@ -107,7 +105,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 	if(uri== NULL)
 	{
 		LM_ERR("no more memory\n");
-		return -1;
+		goto error;
 	}
 	memcpy(uri, pto->uri.s, pto->uri.len);
 	uri[pto->uri.len]= '\0';
@@ -115,12 +113,13 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 	if(to_uri.s== NULL)
 	{
 		LM_ERR("while decoding sip uri in xmpp\n");
-		return -1;	
+		pkg_free(uri);
+		goto error;
 	}	
 	to_uri.len= strlen(to_uri.s);
 	pkg_free(uri);
 
-    if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
+	if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
 	{  
 		LM_ERR("to tag value not parsed\n");
 		goto error;
@@ -166,6 +165,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 	if(from_uri.s== NULL)
 	{
 		LM_ERR("while encoding sip uri in xmpp\n");
+		pkg_free(uri);
 		goto error;
 	}	
 	from_uri.len= strlen(from_uri.s);
@@ -244,7 +244,6 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 			LM_ERR("in function build_xmpp_content\n");	
 			goto error;
 		}
-		xmlFreeDoc(doc);
 	}	
 	else
 	{	
@@ -278,11 +277,11 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
 		}
 
 	}
+	free_to_params(&TO);
 	return 1;
 
 error:
-	if(doc)
-		xmlFreeDoc(doc);
+	free_to_params(&TO);
 	return 0;
 }
 
@@ -793,6 +792,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
 	if(to_uri.s== NULL)
 	{
 		LM_ERR("whil decoding sip uri in xmpp\n");
+		pkg_free(uri);
 		goto error;	
 	}	
 
@@ -811,6 +811,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
 	if(from_uri.s== NULL)
 	{
 		LM_ERR("while encoding sip uri in xmpp\n");
+		pkg_free(uri);
 		goto error;
 	}
 

+ 12 - 11
modules_k/pv/pv_trans.c

@@ -1030,9 +1030,10 @@ int tr_eval_nameaddr(struct sip_msg *msg, tr_param_t *tp, int subtype,
 	{
 		if(val->rs.len>_tr_nameaddr_str.len)
 		{
-			if(_tr_nameaddr_str.s) pkg_free(_tr_nameaddr_str.s);
-			_tr_nameaddr_str.s =
-						(char*)pkg_malloc((val->rs.len+1)*sizeof(char));
+			if(_tr_nameaddr_str.s)
+				pkg_free(_tr_nameaddr_str.s);
+			_tr_nameaddr_str.s = (char*)pkg_malloc((val->rs.len+1)*sizeof(char));
+
 			if(_tr_nameaddr_str.s==NULL)
 			{
 				LM_ERR("no more private memory\n");
@@ -1086,7 +1087,7 @@ int tr_eval_nameaddr(struct sip_msg *msg, tr_param_t *tp, int subtype,
 }
 
 static str _tr_tobody_str = {0, 0};
-static struct to_body _tr_tobody;
+static struct to_body _tr_tobody = {0};
 
 /*!
  * \brief Evaluate To-Body transformations
@@ -1107,18 +1108,18 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
 	if(_tr_tobody_str.len==0 || _tr_tobody_str.len!=val->rs.len ||
 			strncmp(_tr_tobody_str.s, val->rs.s, val->rs.len)!=0)
 	{
-		if(_tr_tobody_str.len==0)
-			memset(&_tr_tobody, 0, sizeof(struct to_body));
 		if(_tr_tobody_str.s==NULL || val->rs.len>_tr_tobody_str.len)
 		{
-			if(_tr_tobody_str.s) pkg_free(_tr_tobody_str.s);
-				_tr_tobody_str.s =
-						(char*)pkg_malloc((val->rs.len+3)*sizeof(char));
+			if(_tr_tobody_str.s)
+				pkg_free(_tr_tobody_str.s);
+			_tr_tobody_str.s = (char*)pkg_malloc((val->rs.len+3)*sizeof(char));
+
 			if(_tr_tobody_str.s==NULL)
 			{
 				LM_ERR("no more private memory\n");
-				memset(&_tr_tobody_str, 0, sizeof(str));
+				free_to_params(&_tr_tobody);
 				memset(&_tr_tobody, 0, sizeof(struct to_body));
+				memset(&_tr_tobody_str, 0, sizeof(str));
 				return -1;
 			}
 		}
@@ -1137,6 +1138,7 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
 		parse_to(sv.s, sv.s + sv.len + 2, &_tr_tobody);
 		if (_tr_tobody.error == PARSE_ERROR)
 		{
+			free_to_params(&_tr_tobody);
 			memset(&_tr_tobody, 0, sizeof(struct to_body));
 			pkg_free(_tr_tobody_str.s);
 			memset(&_tr_tobody_str, 0, sizeof(str));
@@ -1151,7 +1153,6 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
 			memset(&_tr_tobody_str, 0, sizeof(str));
 			return -1;
 		}
-
 	}
 	
 	memset(val, 0, sizeof(pv_value_t));

+ 10 - 9
modules_k/rls/resource_notify.c

@@ -510,7 +510,7 @@ error:
 
 int rls_handle_notify(struct sip_msg* msg, char* c1, char* c2)
 {
-	struct to_body *pto, TO, *pfrom= NULL;
+	struct to_body *pto, TO = {0}, *pfrom = NULL;
 	str body= {0, 0};
 	ua_pres_t dialog;
 	str* res_id= NULL;
@@ -543,22 +543,21 @@ int rls_handle_notify(struct sip_msg* msg, char* c1, char* c2)
 	{
 		LM_ERR("cannot parse TO header\n");
 		return -1;
-    }
+	}
 	if(msg->to->parsed != NULL)
-    {
+	{
 		pto = (struct to_body*)msg->to->parsed;
 		LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",
 				pto->uri.len, pto->uri.s );	
 	}
 	else
 	{
-		memset( &TO , 0, sizeof(TO) );
 		parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
 		if(TO.uri.len <= 0) 
 		{
 			LM_ERR(" 'To' header NOT parsed\n");
-			return -1;
-	}
+			goto error;
+		}
 		pto = &TO;
 	}
 	memset(&dialog, 0, sizeof(ua_pres_t));
@@ -588,8 +587,8 @@ int rls_handle_notify(struct sip_msg* msg, char* c1, char* c2)
 		if ( parse_from_header( msg )<0 ) 
 		{
 			LM_ERR("cannot parse From header\n");
-            goto error;
-        }
+			goto error;
+		}
 	}
 	pfrom = (struct to_body*)msg->from->parsed;
 	dialog.pres_uri= &pfrom->uri;
@@ -790,6 +789,7 @@ done:
 		pkg_free(res_id->s);
 		pkg_free(res_id);
 	}
+	free_to_params(&TO);
 	return 1;
 
 error:
@@ -798,8 +798,9 @@ error:
 		pkg_free(res_id->s);
 		pkg_free(res_id);
 	}
+	free_to_params(&TO);
 	return -1;
-	}
+}
 /* callid, from_tag, to_tag parameters must be allocated */
 
 void timer_send_notify(unsigned int ticks,void *param)