Browse code

- free shm-cloned via lumps bug fixed (triggered by forwarding statlessly a message, then forwarding it statefully and setting a failure_route). Closes: SER-55

Andrei Pelinescu-Onciul authored on 04/07/2005 15:52:11
Showing 4 changed files
... ...
@@ -57,7 +57,7 @@ MAIN_NAME=ser
57 57
 VERSION = 0
58 58
 PATCHLEVEL = 10
59 59
 SUBLEVEL =   99
60
-EXTRAVERSION = -dev9-new_tcp
60
+EXTRAVERSION = -dev10
61 61
 
62 62
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
63 63
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -373,9 +373,17 @@ struct lump* anchor_lump(struct sip_msg* msg, int offset, int len, enum _hdr_typ
373 373
 void free_lump(struct lump* lmp)
374 374
 {
375 375
 	if (lmp && (lmp->op==LUMP_ADD)){
376
-		if (lmp->u.value) pkg_free(lmp->u.value);
377
-		lmp->u.value=0;
378
-		lmp->len=0;
376
+		if (lmp->u.value){
377
+			if (lmp->flags &(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)){
378
+				LOG(L_CRIT, "BUG: free_lump: called on a not free-able lump:"
379
+						"%p flags=%x\n", lmp, lmp->flags);
380
+				abort();
381
+			}else{
382
+				pkg_free(lmp->u.value);
383
+				lmp->u.value=0;
384
+				lmp->len=0;
385
+			}
386
+		}
379 387
 	}
380 388
 }
381 389
 
... ...
@@ -35,6 +35,8 @@
35 35
  * -------
36 36
  *  2003-11-24  changed free_via_lump to free_via_clen_lump and make it
37 37
  *              handle CONTENTLENGTH lumps also (andrei)
38
+ *  2005-07-04  lumps in SHM or dup'ed lumps are not freed and an warning
39
+ *               message is logged (temporary fix) (andrei)
38 40
  */
39 41
 
40 42
 
... ...
@@ -67,21 +69,33 @@ inline static void free_via_clen_lump( struct lump **list )
67 67
 	for(lump=*list;lump;lump=next) {
68 68
 		next=lump->next;
69 69
 		if (lump->type==HDR_VIA_T||lump->type==HDR_CONTENTLENGTH_T) {
70
+			if (lump->flags & (LUMPFLAG_DUPED|LUMPFLAG_SHMEM)){
71
+				LOG(L_CRIT, "BUG: free_via_clen_lmp: lump %p, flags %x\n",
72
+						lump, lump->flags);
73
+				/* ty to continue */
74
+			}
70 75
 			a=lump->before;
71 76
 			while(a) {
72 77
 				foo=a; a=a->before;
73
-				free_lump(foo);
74
-				pkg_free(foo);
78
+				if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
79
+					free_lump(foo);
80
+				if (!(foo->flags&LUMPFLAG_SHMEM))
81
+					pkg_free(foo);
75 82
 			}
76 83
 			a=lump->after;
77 84
 			while(a) {
78 85
 				foo=a; a=a->after;
79
-				free_lump(foo);
80
-				pkg_free(foo);
86
+				if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
87
+					free_lump(foo);
88
+				if (!(foo->flags&LUMPFLAG_SHMEM))
89
+					pkg_free(foo);
81 90
 			}
82 91
 			if (prev_lump) prev_lump->next = lump->next;
83 92
 			else *list = lump->next;
84
-			free_lump(lump);pkg_free(lump);
93
+			if (!(lump->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
94
+				free_lump(lump);
95
+			if (!(lump->flags&LUMPFLAG_SHMEM))
96
+				pkg_free(lump);
85 97
 		} else {
86 98
 			/* store previous position */
87 99
 			prev_lump=lump;
... ...
@@ -60,6 +60,7 @@
60 60
 #include "t_cancel.h"
61 61
 #include "t_stats.h"
62 62
 #include "h_table.h"
63
+#include "fix_lumps.h" /* free_via_clen_lump */
63 64
 
64 65
 static enum kill_reason kr;
65 66
 
... ...
@@ -255,6 +256,9 @@ struct cell*  build_cell( struct sip_msg* p_msg )
255 255
 		run_reqin_callbacks( new_cell, p_msg, p_msg->REQ_METHOD);
256 256
 
257 257
 	if (p_msg) {
258
+		/* clean possible previous added vias/clen header or else they would 
259
+		 * get propagated in the failure routes */
260
+		free_via_clen_lump(&p_msg->add_rm);
258 261
 		new_cell->uas.request = sip_msg_cloner(p_msg,&sip_msg_len);
259 262
 		if (!new_cell->uas.request)
260 263
 			goto error;