add: error03: if (rport_buf) pkg_free(rport_buf);
context: char * build_req_buf_from_sip_req( struct sip_msg* msg,								unsigned int *returned_len,								struct socket_info* send_sock, int proto){	unsigned int len, new_len, received_len, uri_len, via_len;	char* line_buf;	char* received_buf;	char* new_buf;	char* orig;	char* buf;	char  backup;	unsigned int offset, s_offset, size;	struct lump* anchor;	int r;	uri_len=0;	orig=msg->orig;	buf=msg->buf;	len=msg->len;	received_len=0;	new_buf=0;	received_buf=0;	line_buf = via_builder( &via_len, send_sock, 		msg->add_to_branch_s, msg->add_to_branch_len, proto);	if (!line_buf){		LOG(L_ERR,"ERROR: build_req_buf_from_sip_req: no via received!\n");		goto error00;	}	/* check if received needs to be added */	backup = msg->via1->host.s[msg->via1->host.len];	msg->via1->host.s[msg->via1->host.len] = 0;	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);	msg->via1->host.s[msg->via1->host.len] = backup;	if (r!=0){		if ((received_buf=received_builder(msg,&received_len))==0)			goto error01;  /* free also line_buf */	}	/* add via header to the list */	/* try to add it before msg. 1st via */	/* add first via, as an anchor for second via*/	anchor=anchor_lump(&(msg->add_rm), msg->via1->hdr.s-buf, 0, HDR_VIA);	if (anchor==0) goto error01;	if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)		goto error01;	/* if received needs to be added, add anchor after host and add it */	if (received_len){		if (msg->via1->params.s){				size= msg->via1->params.s-msg->via1->hdr.s-1; /*compensate															  for ';' */		}else{				size= msg->via1->host.s-msg->via1->hdr.s+msg->via1->host.len;				if (msg->via1->port!=0){					/*size+=strlen(msg->via1->hdr.s+size+1)+1;*/					size += msg->via1->port_str.len + 1; /* +1 for ':'*/				}			#ifdef USE_IPV6				if(send_sock->address.af==AF_INET6) size+=1; /* +1 for ']'*/			#endif		}		anchor=anchor_lump(&(msg->add_rm),msg->via1->hdr.s-buf+size,0,				HDR_VIA);		if (anchor==0) goto error02; /* free also line_buf */		if (insert_new_lump_after(anchor, received_buf, received_len, HDR_VIA)				==0 ) goto error02; /* free also line_buf */	}	/* compute new msg len and fix overlapping zones*/	new_len=len+lumps_len(msg->add_rm);	if (msg->new_uri.s){		uri_len=msg->new_uri.len;		new_len=new_len-msg->first_line.u.request.uri.len+uri_len;	}	new_buf=(char*)pkg_malloc(new_len+1);	if (new_buf==0){		ser_error=E_OUT_OF_MEM;		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: out of memory\n");		goto error00;	}	offset=s_offset=0;	if (msg->new_uri.s){		/* copy message up to uri */		size=msg->first_line.u.request.uri.s-buf;		memcpy(new_buf, orig, size);		offset+=size;		s_offset+=size;		/* add our uri */		memcpy(new_buf+offset, msg->new_uri.s, uri_len);		offset+=uri_len;		s_offset+=msg->first_line.u.request.uri.len; /* skip original uri */	}	new_buf[new_len]=0;	/* copy msg adding/removing lumps */	process_lumps(msg->add_rm, new_buf, &offset, orig, &s_offset);	/* copy the rest of the message */	memcpy(new_buf+offset, orig+s_offset, len-s_offset);	new_buf[new_len]=0;#ifdef DBG_MSG_QA	if (new_buf[new_len-1]==0) {		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: 0 in the end\n");		abort();	}#endif	*returned_len=new_len;	return new_buf;error01:	pkg_free(line_buf);error02:	if (received_buf) pkg_free(received_buf);error00:	*returned_len=0;	return 0;}