Browse code

minor fixes

Jiri Kuthan authored on 07/12/2001 00:32:22
Showing 1 changed files
... ...
@@ -16,12 +16,28 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
16 16
 
17 17
     /* clones the sip_msg structure */
18 18
     new_msg = (struct sip_msg*)sh_malloc( sizeof( struct sip_msg) );
19
-    if (!new_msg) return NULL;
19
+    if (!new_msg) {
20
+	DBG("DEBUG: sip_msg_cloner: sip_msg allocation failed\n");
21
+	return NULL;
22
+    }
20 23
     memcpy( new_msg , org_msg , sizeof( struct sip_msg) );
21 24
 
25
+    /* if something bad happens during the allocation process,
26
+       don't try to release pointers which were cloned
27
+    */
28
+    new_msg->new_uri.s=NULL;
29
+    new_msg->headers=NULL;
30
+    new_msg->add_rm=NULL;
31
+    new_msg->repl_add_rm=NULL;
32
+    new_msg->orig=NULL;
33
+    new_msg->buf=NULL;
34
+
35
+
36
+
22 37
     /* the original message - orig ( char*  type) */
23 38
     new_msg->orig = (char*)sh_malloc( new_msg->len+1 );
24 39
     if (!new_msg->orig) {
40
+	DBG("DEBUG: sip_msg_cloner: new_msg->orig allocation failed\n");
25 41
 	goto error;
26 42
     }
27 43
     memcpy( new_msg->orig , org_msg->orig, new_msg->len );
... ...
@@ -30,6 +46,7 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
30 46
     /* the scratch pad - buf ( char* type) */
31 47
     new_msg->buf = (char*)sh_malloc( new_msg->len+1 );
32 48
     if (!new_msg->buf) {
49
+	DBG("DEBUG: sip_msg_cloner:  new_msg->buf allocation failed\n");
33 50
 	goto error;
34 51
     }
35 52
     memcpy( new_msg->buf , org_msg->buf, new_msg->len );
... ...
@@ -64,7 +81,10 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
64 81
     /* new_uri  ( str type )*/
65 82
 	if (org_msg->new_uri.s){ 
66 83
 		if (!(new_msg->new_uri.s = (char*)sh_malloc( org_msg->new_uri.len )))
84
+		{
85
+			DBG("DEBUG: sip_msg_cloner: new_msg->new_uri.s allocation failed\n");
67 86
 			goto error;
87
+		}
68 88
 		memcpy( new_msg->new_uri.s , org_msg->new_uri.s ,
69 89
 				org_msg->new_uri.len );
70 90
 	}
... ...
@@ -80,8 +100,10 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
80 100
     for( header = org_msg->headers , last_hdr=0  ;  header ; header=header->next)
81 101
     {
82 102
 	new_hdr = header_cloner( new_msg , org_msg , header );
83
-	if (!new_hdr) 
103
+	if (!new_hdr) {
104
+		DBG("DEBUG: sip_msg_cloner: new_hdr allocation failed\n");
84 105
 		goto error;
106
+	}
85 107
 	switch ( header->type )
86 108
 	{
87 109
 	    case HDR_VIA :
... ...
@@ -89,7 +111,10 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
89 111
 		{
90 112
 		    new_msg->h_via1 = new_hdr;
91 113
 		    new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
92
-		    if (!new_msg->via1) goto hf_error;
114
+		    if (!new_msg->via1) {
115
+			DBG("DEBUG: sip_msg_cloner:  new_msg->via1 allocation failed\n");
116
+			goto hf_error;
117
+		    }
93 118
 		    
94 119
 		    new_hdr->parsed  = (void*)new_msg->via1;
95 120
 		     if ( new_msg->via1->next )
... ...
@@ -102,14 +127,20 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
102 127
 		        new_hdr->parsed = (void*)new_msg->via1->next;
103 128
 		     else{
104 129
 		        new_msg->via2 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
105
-			if (!new_msg->via2) goto hf_error;
130
+			if (!new_msg->via2) {
131
+				DBG("DEBUG: sip_msg_cloner:  new_msg->via2 allocation failed\n");
132
+				goto hf_error;
133
+			}
106 134
 		        new_hdr->parsed  = (void*)new_msg->via2;
107 135
 		     }
108 136
 		}
109 137
 		else if ( new_msg->via2 && new_msg->via1 )
110 138
 		{
111 139
 		    new_hdr->parsed  = new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
112
-		    if (!new_hdr->parsed) goto hf_error;
140
+		    if (!new_hdr->parsed) {
141
+				DBG("DEBUG: sip_msg_cloner:  new_hdr->parsed  via1 allocation failed\n");
142
+				goto hf_error;
143
+		    }
113 144
 		}
114 145
 		break;
115 146
 	    case HDR_FROM :
... ...
@@ -122,7 +153,10 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
122 153
 		if (header->parsed)
123 154
 		{
124 155
 		  new_hdr->parsed = (void*)sh_malloc( sizeof(struct cseq_body) );
125
-		  if (!new_hdr->parsed) goto hf_error;
156
+		  if (!new_hdr->parsed) {
157
+			DBG("DEBUG: sip_msg_cloner:  new_hdr->parsed  cseq allocation failed\n");
158
+			goto hf_error;
159
+		  }
126 160
 		  memcpy( new_hdr->parsed , header->parsed , sizeof(struct cseq_body) );
127 161
 		  ((struct cseq_body*)new_hdr->parsed)->number.s = translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)header->parsed)->number.s );
128 162
 		  ((struct cseq_body*)new_hdr->parsed)->method.s = translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)header->parsed)->method.s );