浏览代码

- fixed newly introduce malloc bug

Andrei Pelinescu-Onciul 24 年之前
父节点
当前提交
6bd84753fe
共有 4 个文件被更改,包括 16 次插入12 次删除
  1. 1 1
      Makefile
  2. 6 2
      mem.h
  3. 3 3
      msg_parser.c
  4. 6 6
      udp_server.c

+ 1 - 1
Makefile

@@ -28,7 +28,7 @@ NAME=ser
 # DEBUG compiles in some extra debugging code
 # OLD_PARSER uses the old and stable parser (from ser 8.3.2)
 # DNS_IP_HACK faster ip address resolver for ip strings (e.g "127.0.0.1")
-DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK -DSTATS #-DNO_DEBUG#-DSTATS -DNO_DEBUG 
+DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK #-DNO_DEBUG#-DSTATS -DNO_DEBUG 
 #-DNO_LOG
 
 PROFILE=  # -pg #set this if you want profiling

+ 6 - 2
mem.h

@@ -7,6 +7,7 @@
 
 #ifndef mem_h
 #define mem_h
+#include "dprint.h"
 
 #ifdef PKG_MALLOC
 #include "q_malloc.h"
@@ -21,8 +22,11 @@ extern struct qm_block* mem_block;
 #else
 #include <stdlib.h>
 
-#define pkg_malloc(s) malloc(s)
-#define pkg_free(p)  free(p)
+#define pkg_malloc(s) \
+	(  { void *v; v=malloc(s); \
+	   DBG("malloc %x size %d end %x\n", v, s, (unsigned int)v+s);\
+	   v; } )
+#define pkg_free(p)  do{ DBG("free %x\n", p); free(p); }while(0);
 #define pkg_status()
 
 #endif

+ 3 - 3
msg_parser.c

@@ -920,11 +920,11 @@ void free_hdr_field_lst(struct hdr_field* hf)
 void free_sip_msg(struct sip_msg* msg)
 {
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
-	if (msg->headers) 	  free_hdr_field_lst(msg->headers);
+	if (msg->headers)     free_hdr_field_lst(msg->headers);
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
 	if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm);
-	free(msg->orig);
-	free(msg->buf);
+	pkg_free(msg->orig);
+	pkg_free(msg->buf);
 }
 
 

+ 6 - 6
udp_server.c

@@ -154,12 +154,6 @@ int udp_rcv_loop()
 	struct sockaddr* from;
 	int fromlen;
 
-	buf=pkg_malloc(BUF_SIZE+1);
-	if (buf==0){
-		LOG(L_ERR, "ERROR: udp_rcv_loop: could not allocate receive"
-				 " buffer\n");
-		goto error;
-	}
 	from=(struct sockaddr*) malloc(sizeof(struct sockaddr));
 	if (from==0){
 		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
@@ -167,6 +161,12 @@ int udp_rcv_loop()
 	}
 
 	for(;;){
+		buf=pkg_malloc(BUF_SIZE+1);
+		if (buf==0){
+			LOG(L_ERR, "ERROR: udp_rcv_loop: could not allocate receive"
+					 " buffer\n");
+			goto error;
+		}
 		fromlen=sizeof(struct sockaddr);
 		len=recvfrom(udp_sock, buf, BUF_SIZE, 0, from, &fromlen);
 		if (len==-1){