rem: if ( T->inbound_response ) { sh_free( T->inbound_response->buffer ); } else { struct hostent  *nhost; unsigned int      ip, port; char foo;
add: buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len ); DBG("DEBUG: t_send_reply: after build\n"); if (!buf) { DBG("DEBUG: t_send_reply: response building failed\n"); goto error; }
context: int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text ){   t_check( hash_table, p_msg );   if (T)   {      unsigned int len;      char * buf;      buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len );         DBG("DEBUG: t_send_reply: after build\n");      if (!buf)      {         DBG("DEBUG: t_send_reply: response building failed\n");         return -1;      }     if ( T->inbound_response )      {         sh_free( T->inbound_response->buffer );      }      else      {         struct hostent  *nhost;         unsigned int      ip, port;         char foo;          /*some dirty trick to get the port from via */          foo = *((p_msg->via1->host.s)+(p_msg->via1->host.len));          *((p_msg->via1->host.s)+(p_msg->via1->host.len)) = 0;          nhost = gethostbyname( p_msg->via1->host.s );          *((p_msg->via1->host.s)+(p_msg->via1->host.len)) = foo;          if ( !nhost )          {             DBG("ERROR: t_send_reply: resolving host failed\n");             free(buf);             return -1;          }          memcpy( &ip , nhost->h_addr_list[0] , sizeof(unsigned int) );          /* port */          if ( !(port = p_msg->via1->port) )             port = SIP_PORT;          /* build a retrans_buff and fill it */          T->inbound_response = (struct retrans_buff*)sh_malloc( sizeof(struct retrans_buff) );          memset( T->inbound_response , 0 , sizeof (struct retrans_buff) );          T->inbound_response->tl[RETRASMISSIONS_LIST].payload = T->inbound_response;          T->inbound_response->tl[FR_TIMER_LIST].payload = T->inbound_response;          T->inbound_response->to.sin_family = AF_INET;          T->inbound_response->my_T = T;          T->inbound_response->to.sin_addr.s_addr = ip;          T->inbound_response->to.sin_port =  htons(port);          T->inbound_response->dest_ip       = ip;          T->inbound_response->dest_port    = htons(port);      }      T->status = code;      T->inbound_response->bufflen = len ;      T->inbound_response->buffer   = (char*)sh_malloc( len );      memcpy( T->inbound_response->buffer , buf , len );      free( buf ) ;      /* make sure that if we send something final upstream, everything else will be cancelled */      if ( code>=200 )         if ( p_msg->first_line.u.request.method_value==METHOD_INVITE )         {            T->inbound_response->timeout_ceiling  = RETR_T2;            T->inbound_response->timeout_value    = RETR_T1;            remove_from_timer_list( hash_table , &(T->inbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );            insert_into_timer_list( hash_table , &(T->inbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST , RETR_T1 );            remove_from_timer_list( hash_table , &(T->inbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST );            insert_into_timer_list( hash_table , &(T->inbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST , FR_TIME_OUT );         }         else         {            t_put_on_wait( p_msg );         }      udp_send( T->inbound_response->buffer , T->inbound_response->bufflen , (struct sockaddr*)&(T->inbound_response->to) , sizeof(struct sockaddr_in) );   }   return 1;}