rem: t_reply( t, t->uas.request, 500, "Reply processing error" );
context: enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, 	unsigned int msg_status, branch_bm_t *cancel_bitmap ){	int relay;	int save_clone;	char *buf;	/* length of outbound reply */	unsigned int res_len;	int relayed_code;	struct sip_msg *relayed_msg;	str	to_tag;	enum rps reply_status;	/* retransmission structure of outbound reply and request */	struct retr_buf *uas_rb;	/* keep compiler warnings about use of uninit vars silent */	res_len=0;	buf=0;	relayed_msg=0;	relayed_code=0;	/* remember, what was sent upstream to know whether we are	   forwarding a first final reply or not */	/* *** store and relay message as needed *** */	reply_status = t_should_relay_response(t, msg_status, branch, 		&save_clone, &relay, cancel_bitmap );	DBG("DEBUG: relay_reply: branch=%d, save=%d, relay=%d\n",		branch, save_clone, relay );	/* store the message if needed */	if (save_clone) /* save for later use, typically branch picking */	{		if (!store_reply( t, branch, p_msg ))			goto error01;	}	uas_rb = & t->uas.response;	if (relay >= 0 ) {		/* initialize sockets for outbound reply */		uas_rb->activ_type=msg_status;		/* only messages known to be relayed immediately will be		   be called on; we do not evoke this callback on messages		   stored in shmem -- they are fixed and one cannot change them		   anyway         */		if (msg_status<300 && branch==relay) {			callback_event( TMCB_REPLY_IN, t, p_msg, msg_status );		}		/* try bulding the outbound reply from either the current	       or a stored message */		relayed_msg = branch==relay ? p_msg :  t->uac[relay].reply;		if (relayed_msg ==FAKED_REPLY) {			relayed_code = branch==relay				? msg_status : t->uac[relay].last_received;			buf = build_res_buf_from_sip_req( relayed_code,				error_text(relayed_code), 0,0, /* no to-tag */				t->uas.request, &res_len );		} else {			relayed_code=relayed_msg->REPLY_STATUS;			buf = build_res_buf_from_sip_res( relayed_msg, &res_len );			/* if we build a message from shmem, we need to remove			   via delete lumps which are now stirred in the shmem-ed			   structure			*/			if (branch!=relay) {				free_via_lump(&relayed_msg->repl_add_rm);			}		}		update_reply_stats( relayed_code );		if (!buf) {			LOG(L_ERR, "ERROR: relay_reply: "				"no mem for outbound reply buffer\n");			goto error02;		}		/* attempt to copy the message to UAS's shmem:		   - copy to-tag for ACK matching as well		   -  allocate little a bit more for provisionals as		      larger messages are likely to follow and we will be 		      able to reuse the memory frag 		*/		uas_rb->buffer = (char*)shm_resize( uas_rb->buffer, res_len +			(msg_status<200 ?  REPLY_OVERBUFFER_LEN : 0));		if (!uas_rb->buffer) {			LOG(L_ERR, "ERROR: relay_reply: cannot alloc reply shmem\n");			goto error03;		}		uas_rb->buffer_len = res_len;		memcpy( uas_rb->buffer, buf, res_len );		/* to tag now */		if (relayed_code>=300 && t->is_invite) {			if (relayed_msg!=FAKED_REPLY) {				to_tag=get_to(relayed_msg)->tag_value;				t->uas.to_tag.s=(char *)shm_resize( t->uas.to_tag.s,					to_tag.len );				if (!t->uas.to_tag.s) {					LOG(L_ERR, "ERROR: no shmem for to-tag\n");					goto error04;				}				t->uas.to_tag.len=to_tag.len;				memcpy(t->uas.to_tag.s, to_tag.s, to_tag.len );			} else {				if (t->uas.to_tag.s) shm_free(t->uas.to_tag.s);				t->uas.to_tag.s=0;				t->uas.to_tag.len=0;			}		}		/* update the status ... */		t->uas.status = relayed_code;		t->relaied_reply_branch = relay;	}; /* if relay ... */	UNLOCK_REPLIES( t );	/* send it now (from the private buffer) */	if (relay >= 0) {		SEND_PR_BUFFER( uas_rb, buf, res_len );		DBG("DEBUG: reply relayed. buf=%p: %.9s..., shmem=%p: %.9s\n", 			buf, buf, uas_rb->buffer, uas_rb->buffer );		callback_event( TMCB_REPLY, t, relayed_msg, relayed_code );		pkg_free( buf );	}	/* success */	return reply_status;error04:	shm_free( uas_rb->buffer );	uas_rb->buffer=0;error03:	pkg_free( buf );error02:	if (save_clone) {		if (t->uac[branch].reply!=FAKED_REPLY)			sip_msg_free( t->uac[branch].reply );		t->uac[branch].reply = NULL;		}error01:	UNLOCK_REPLIES(t);	if (t->is_invite) cancel_uacs( t, *cancel_bitmap );	/* a serious error occured -- attempt to send an error reply;	   it will take care of clean-ups 	*/	t_reply( t, t->uas.request, 500, "Reply processing error" );	/* failure */	return RPS_ERROR;}