Browse code

tm: _reply cleans up after itself

The _reply() function now cleans possible added reply_lumps before
exiting. This allows using it not only from request or failure
route.

Andrei Pelinescu-Onciul authored on 22/02/2010 16:48:45
Showing 1 changed files
... ...
@@ -92,6 +92,8 @@
92 92
  * 2009-06-01  Pre- and post-script callbacks of branch route are 
93 93
  *             executed (Miklos)
94 94
  * 2009-12-10  reply route is executed under lock to protect the avps (andrei)
95
+ * 2010-02-22  _reply() will cleanup any reply lumps that it might have added
96
+ *             (andrei)
95 97
  *
96 98
  */
97 99
 
... ...
@@ -653,7 +655,9 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
653 653
 	char * buf, *dset;
654 654
 	struct bookmark bm;
655 655
 	int dset_len;
656
+	struct lump_rpl* rpl_l;
656 657
 
658
+	rpl_l=0;
657 659
 	if (code>=200) set_kr(REQ_RPLD);
658 660
 	/* compute the buffer in private memory prior to entering lock;
659 661
 	 * create to-tag if needed */
... ...
@@ -671,12 +675,19 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
671 671
 			    || get_to(p_msg)->tag_value.len==0)) {
672 672
 		calc_crc_suffix( p_msg, tm_tag_suffix );
673 673
 		buf = build_res_buf_from_sip_req(code,text, &tm_tag, p_msg, &len, &bm);
674
+		if (unlikely(rpl_l)){
675
+			unlink_lump_rpl(p_msg, rpl_l);
676
+			free_lump_rpl(rpl_l);
677
+		}
674 678
 		return _reply_light( trans, buf, len, code, text,
675 679
 			tm_tag.s, TOTAG_VALUE_LEN, lock, &bm);
676 680
 	} else {
677 681
 		buf = build_res_buf_from_sip_req(code,text, 0 /*no to-tag*/,
678 682
 			p_msg, &len, &bm);
679
-
683
+		if (unlikely(rpl_l)){
684
+			unlink_lump_rpl(p_msg, rpl_l);
685
+			free_lump_rpl(rpl_l);
686
+		}
680 687
 		return _reply_light(trans,buf,len,code,text,
681 688
 			0, 0, /* no to-tag */lock, &bm);
682 689
 	}