rem: goto error01;
add: goto error00;
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, rport_len, uri_len, via_len;	char* line_buf;	char* received_buf;	char* rport_buf;	char* new_buf;	char* buf;	unsigned int offset, s_offset, size;	struct lump* anchor;	struct lump* via_insert_param;	str branch;	str extra_params;	#ifdef USE_TCP	char* id_buf;	unsigned int id_len;	char* clen_buf;	unsigned int clen_len;			id_buf=0;	id_len=0;	clen_buf=0;	clen_len=0;#endif	via_insert_param=0;	extra_params.len=0;	extra_params.s=0;	uri_len=0;	buf=msg->buf;	len=msg->len;	received_len=0;	rport_len=0;	new_buf=0;	received_buf=0;	rport_buf=0;	line_buf=0;	#ifdef USE_TCP	/* add id if tcp */	if (msg->rcv.proto==PROTO_TCP#ifdef USE_TLS			|| msg->rcv.proto==PROTO_TLS#endif			){		if  ((id_buf=id_builder(msg, &id_len))==0){			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"							" id_builder failed\n");			goto error01; /* free everything */		}		DBG("build_req_from_req: id added: <%.*s>, rcv proto=%d\n",				(int)id_len, id_buf, msg->rcv.proto);		extra_params.s=id_buf;		extra_params.len=id_len;	}	/* if sending proto == tcp, check if Content-Length needs to be added*/	if (proto==PROTO_TCP#ifdef USE_TLS			|| proto==PROTO_TLS#endif			){		DBG("build_req_from_req: checking for clen; proto=%d,"			" rcv->proto=%d\n", proto, msg->rcv.proto);		/* first of all parse content-length */		if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){			LOG(L_ERR, "build_req_buf_from_sip_req:"							" error parsing content-length\n");			goto skip_clen;		}		if (msg->content_length==0){			/* we need to add it */			if ((clen_buf=clen_builder(msg, &clen_len))==0){				LOG(L_ERR, "build_req_buf_from_sip_req:" 								" clen_builder failed\n");				goto skip_clen;			}		}	}skip_clen:#endif	branch.s=msg->add_to_branch_s;	branch.len=msg->add_to_branch_len;	line_buf = via_builder( &via_len, send_sock, &branch,							extra_params.len?&extra_params:0, 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 */	if ( msg->via1->received || 			check_via_address(&msg->rcv.src_ip, &msg->via1->host, 									msg->via1->port, received_dns) ){		if ((received_buf=received_builder(msg,&received_len))==0){			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"							" received_builder failed\n");			goto error01;  /* free also line_buf */		}	}		/* check if rport needs to be updated:	 *  - if FL_FORCE_RPORT is set add it (and del. any previous version)	 *  - if via already contains an rport add it and overwrite the previous	 *  rport value if present (if you don't want to overwrite the previous	 *  version remove the comments) */	if ((msg->msg_flags&FL_FORCE_RPORT)||			(msg->via1->rport /*&& msg->via1->rport->value.s==0*/)){		if ((rport_buf=rport_builder(msg, &rport_len))==0){			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"							" rport_builder failed\n");			goto error01; /* free everything */		}	}	/* 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;	/* find out where the offset of the first parameter that should be added	 * (after host:port), needed by add receive & maybe rport */	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 ':'*/			}#if 0			/* no longer necessary, now hots.s contains [] */		#ifdef USE_IPV6			if(send_sock->address.af==AF_INET6) size+=1; /* +1 for ']'*/		#endif#endif	}	/* if received needs to be added, add anchor after host and add it, or 	 * overwrite the previous one if already present */	if (received_len){		if (msg->via1->received){ /* received already present => overwrite it*/			via_insert_param=del_lump(&(msg->add_rm),								msg->via1->received->start-buf-1, /*;*/								msg->via1->received->size+1, /*;*/ HDR_VIA);		}else if (via_insert_param==0){ /* receive not present, ok */			via_insert_param=anchor_lump(&(msg->add_rm),										msg->via1->hdr.s-buf+size,0, HDR_VIA);		}		if (via_insert_param==0) goto error02; /* free received_buf */		if (insert_new_lump_after(via_insert_param, received_buf, received_len,					HDR_VIA) ==0 ) goto error02; /* free received_buf */	}	/* if rport needs to be updated, delete it if present and add it's value */	if (rport_len){		if (msg->via1->rport){ /* rport already present */			via_insert_param=del_lump(&(msg->add_rm),								msg->via1->rport->start-buf-1, /*';'*/								msg->via1->rport->size+1 /* ; */, HDR_VIA);		}else if (via_insert_param==0){ /*force rport, no rport present */			/* no rport, add it */			via_insert_param=anchor_lump(&(msg->add_rm),										msg->via1->hdr.s-buf+size,0, HDR_VIA);		}		if (via_insert_param==0) goto error03; /* free rport_buf */		if (insert_new_lump_after(via_insert_param, rport_buf, rport_len,									HDR_VIA) ==0 )			goto error03; /* free rport_buf */				}#ifdef USE_TCP	/* if clen needs to be added, add it */	if (clen_len){		/* msg->unparsed should point just before the final crlf,		 * parse_headers is called from clen_builder */		anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0,							 HDR_CONTENTLENGTH);		if (anchor==0) goto error04; /* free clen_buf*/		if (insert_new_lump_after(anchor, clen_buf, clen_len,					HDR_CONTENTLENGTH)==0)			goto error04; /* free clen_buf*/	}#endif	/* compute new msg len and fix overlapping zones*/	new_len=len+lumps_len(msg, send_sock);#ifdef XL_DEBUG	LOG(L_ERR, "DEBUG: new_len(%d)=len(%d)+lumps_len\n", new_len, len);#endif	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, buf, 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, new_buf, &offset, &s_offset, send_sock);	/* copy the rest of the message */	memcpy(new_buf+offset, buf+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);#ifdef USE_TCP	if (id_buf) pkg_free(id_buf);#endiferror02:	if (received_buf) pkg_free(received_buf);error03:	if (rport_buf) pkg_free(rport_buf);#ifdef USE_TCPerror04:	if (clen_buf) pkg_free(clen_buf);#endiferror00:	*returned_len=0;	return 0;}