Browse code

- fixed newly introduce malloc bug

Andrei Pelinescu-Onciul authored on 23/11/2001 10:02:56
Showing 4 changed files
... ...
@@ -28,7 +28,7 @@ NAME=ser
28 28
 # DEBUG compiles in some extra debugging code
29 29
 # OLD_PARSER uses the old and stable parser (from ser 8.3.2)
30 30
 # DNS_IP_HACK faster ip address resolver for ip strings (e.g "127.0.0.1")
31
-DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK -DSTATS #-DNO_DEBUG#-DSTATS -DNO_DEBUG 
31
+DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK #-DNO_DEBUG#-DSTATS -DNO_DEBUG 
32 32
 #-DNO_LOG
33 33
 
34 34
 PROFILE=  # -pg #set this if you want profiling
... ...
@@ -7,6 +7,7 @@
7 7
 
8 8
 #ifndef mem_h
9 9
 #define mem_h
10
+#include "dprint.h"
10 11
 
11 12
 #ifdef PKG_MALLOC
12 13
 #include "q_malloc.h"
... ...
@@ -21,8 +22,11 @@ extern struct qm_block* mem_block;
21 21
 #else
22 22
 #include <stdlib.h>
23 23
 
24
-#define pkg_malloc(s) malloc(s)
25
-#define pkg_free(p)  free(p)
24
+#define pkg_malloc(s) \
25
+	(  { void *v; v=malloc(s); \
26
+	   DBG("malloc %x size %d end %x\n", v, s, (unsigned int)v+s);\
27
+	   v; } )
28
+#define pkg_free(p)  do{ DBG("free %x\n", p); free(p); }while(0);
26 29
 #define pkg_status()
27 30
 
28 31
 #endif
... ...
@@ -920,11 +920,11 @@ void free_hdr_field_lst(struct hdr_field* hf)
920 920
 void free_sip_msg(struct sip_msg* msg)
921 921
 {
922 922
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
923
-	if (msg->headers) 	  free_hdr_field_lst(msg->headers);
923
+	if (msg->headers)     free_hdr_field_lst(msg->headers);
924 924
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
925 925
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
926
-	free(msg->orig);
927
-	free(msg->buf);
926
+	pkg_free(msg->orig);
927
+	pkg_free(msg->buf);
928 928
 }
929 929
 
930 930
 
... ...
@@ -154,12 +154,6 @@ int udp_rcv_loop()
154 154
 	struct sockaddr* from;
155 155
 	int fromlen;
156 156
 
157
-	buf=pkg_malloc(BUF_SIZE+1);
158
-	if (buf==0){
159
-		LOG(L_ERR, "ERROR: udp_rcv_loop: could not allocate receive"
160
-				 " buffer\n");
161
-		goto error;
162
-	}
163 157
 	from=(struct sockaddr*) malloc(sizeof(struct sockaddr));
164 158
 	if (from==0){
165 159
 		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
... ...
@@ -167,6 +161,12 @@ int udp_rcv_loop()
167 167
 	}
168 168
 
169 169
 	for(;;){
170
+		buf=pkg_malloc(BUF_SIZE+1);
171
+		if (buf==0){
172
+			LOG(L_ERR, "ERROR: udp_rcv_loop: could not allocate receive"
173
+					 " buffer\n");
174
+			goto error;
175
+		}
170 176
 		fromlen=sizeof(struct sockaddr);
171 177
 		len=recvfrom(udp_sock, buf, BUF_SIZE, 0, from, &fromlen);
172 178
 		if (len==-1){