[sr-dev] git:master:6118d832: core: msg translator - reworked error handling to free allocated buffers

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 4 09:01:14 CEST 2017


Module: kamailio
Branch: master
Commit: 6118d832d3ba0efb96820915520af3c8a9bf29de
URL: https://github.com/kamailio/kamailio/commit/6118d832d3ba0efb96820915520af3c8a9bf29de

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-04T09:00:45+02:00

core: msg translator - reworked error handling to free allocated buffers

---

Modified: src/core/msg_translator.c

---

Diff:  https://github.com/kamailio/kamailio/commit/6118d832d3ba0efb96820915520af3c8a9bf29de.diff
Patch: https://github.com/kamailio/kamailio/commit/6118d832d3ba0efb96820915520af3c8a9bf29de.patch

---

diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 618a6ba2e7..1a20d0d005 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -2033,7 +2033,10 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 		}
 		if (via_insert_param==0) goto error02; /* free received_buf */
 		if (insert_new_lump_after(via_insert_param, received_buf, received_len,
-					HDR_VIA_T) ==0 ) goto error02; /* free received_buf */
+					HDR_VIA_T) ==0 ) {
+			goto error02; /* free received_buf */
+		}
+		received_buf = NULL;
 	}
 	/* if rport needs to be updated, delete it if present and add it's value */
 	if (rport_len){
@@ -2048,9 +2051,10 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 		}
 		if (via_insert_param==0) goto error03; /* free rport_buf */
 		if (insert_new_lump_after(via_insert_param, rport_buf, rport_len,
-									HDR_VIA_T) ==0 )
+									HDR_VIA_T) ==0 ) {
 			goto error03; /* free rport_buf */
-
+		}
+		rport_buf = NULL;
 	}
 
 after_update_via1:
@@ -2073,25 +2077,26 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 		   (if present & parsed), after the local via or after in front of
 		    the first via if we don't add a local via*/
 		if (msg->route){
-			path_anchor=anchor_lump(msg, msg->route->name.s-buf, 0, 
+			path_anchor=anchor_lump(msg, msg->route->name.s-buf, 0,
 									HDR_ROUTE_T);
 		}else if (likely(via_anchor)){
 			path_anchor=via_anchor;
 		}else if (likely(msg->via1)){
-			path_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, 
+			path_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0,
 									HDR_ROUTE_T);
 		}else{
 			/* if no via1 (theoretically possible for non-sip messages,
 			   e.g. http xmlrpc) */
-			path_anchor=anchor_lump(msg, msg->headers->name.s-buf, 0, 
+			path_anchor=anchor_lump(msg, msg->headers->name.s-buf, 0,
 									HDR_ROUTE_T);
 		}
 		if (unlikely(path_anchor==0))
 			goto error05;
 		if (unlikely((path_lump=insert_new_lump_after(path_anchor, path_buf.s,
-														path_buf.len,
-														HDR_ROUTE_T))==0))
+									path_buf.len, HDR_ROUTE_T))==0)) {
 			goto error05;
+		}
+		path_buf.s = NULL;
 	}
 	/* compute new msg len and fix overlapping zones*/
 	new_len=len+body_delta+lumps_len(msg, msg->add_rm, send_info)+via_len;
@@ -2100,7 +2105,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 #endif
 	udp_mtu=cfg_get(core, core_cfg, udp_mtu);
 	di.proto=PROTO_NONE;
-	if (unlikely((send_info->proto==PROTO_UDP) && udp_mtu && 
+	if (unlikely((send_info->proto==PROTO_UDP) && udp_mtu &&
 					(flags & FL_MTU_FB_MASK) && (new_len>udp_mtu)
 					&& (!(mode&BUILD_NO_LOCAL_VIA)))){
 
@@ -2127,7 +2132,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 			di.proto=PROTO_SCTP;
 		 }
 #endif /* USE_SCTP */
-		
+
 		if (di.proto!=PROTO_NONE){
 			new_len-=via_len;
 			if(likely(line_buf)) pkg_free(line_buf);
@@ -2144,8 +2149,10 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	/* add first via, as an anchor for second via*/
 	if(likely(line_buf)) {
 		if ((via_lump=insert_new_lump_before(via_anchor, line_buf, via_len,
-											HDR_VIA_T))==0)
+											HDR_VIA_T))==0) {
 			goto error04;
+		}
+		line_buf = 0;
 	}
 	if (msg->new_uri.s){
 		uri_len=msg->new_uri.len;
@@ -2182,7 +2189,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	new_buf[new_len]=0;
 
 	/* update the send_info if udp_mtu affected */
-	if (di.proto!=PROTO_NONE) { 
+	if (di.proto!=PROTO_NONE) {
 		send_info->proto=di.proto;
 		send_info->send_sock=di.send_sock;
 	}
@@ -2199,13 +2206,14 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 
 error01:
 error02:
-	if (received_buf) pkg_free(received_buf);
 error03:
-	if (rport_buf) pkg_free(rport_buf);
 error04:
-	if (line_buf) pkg_free(line_buf);
 error05:
+	if (received_buf) pkg_free(received_buf);
+	if (rport_buf) pkg_free(rport_buf);
 	if (path_buf.s) pkg_free(path_buf.s);
+	if (line_buf) pkg_free(line_buf);
+
 error00:
 	*returned_len=0;
 	return 0;




More information about the sr-dev mailing list