Browse code

in update_from_via : - it gets compile with DBG_QM_MALLOC - avoids an extra malloc/memcpy/free when via is not null terminated

Bogdan-Andrei Iancu authored on 27/06/2002 10:54:13
Showing 1 changed files
... ...
@@ -135,7 +135,8 @@ int update_sock_struct_from_via( union sockaddr_union* to,
135 135
 								 struct via_body* via )
136 136
 {
137 137
 	struct hostent* he;
138
-	char *host_copy;
138
+	//char *host_copy;
139
+	char backup;
139 140
 
140 141
 
141 142
 #ifdef DNS_IP_HACK
... ...
@@ -157,17 +158,27 @@ int update_sock_struct_from_via( union sockaddr_union* to,
157 158
            BTW: when is via->host.s non null terminated? tm copy?
158 159
 		   - andrei 
159 160
 			Yes -- it happened on generating a 408 by TM; -jiri
161
+		   if you consider that via is never placed to the end of
162
+		   the msg buffer (so we can happily work with via->host.s[len]),
163
+		   insted of making a copy, we can simply backup the first caracter
164
+		   after via and put a 0 there -> call resolvehost -> restore it
165
+		   - bogdan
160 166
 		*/
161 167
 		if (via->host.s[via->host.len]){
162
-			host_copy=pkg_malloc( via->host.len+1 );
168
+			/*host_copy = pkg_malloc( via->host.len+1 );
163 169
 			if (!host_copy) {
164
-				LOG(L_NOTICE, "ERROR: update_sock_struct_from_via: not enough memory\n");
170
+				LOG(L_NOTICE, "ERROR: update_sock_struct_from_via:"
171
+					" not enough memory\n");
165 172
 				return -1;
166 173
 			}
167 174
 			memcpy(host_copy, via->host.s, via->host.len );
168 175
 			host_copy[via->host.len]=0;
169 176
 			he=resolvehost(host_copy);
170
-			pkg_free( host_copy );
177
+			pkg_free( host_copy );*/
178
+			backup = via->host.s[via->host.len];
179
+			via->host.s[via->host.len] = 0;
180
+			he=resolvehost(via->host.s);
181
+			via->host.s[via->host.len] = backup;
171 182
 		}else{
172 183
 			he=resolvehost(via->host.s);
173 184
 		}