Browse Source

- replaced all mallocs/frees w/ pkg_malloc/pkg_free
- minor lock_dealloc warning fixes

Andrei Pelinescu-Onciul 22 năm trước cách đây
mục cha
commit
e3dccdc952
17 tập tin đã thay đổi với 173 bổ sung140 xóa
  1. 5 3
      action.c
  2. 7 8
      cfg.lex
  3. 17 15
      cfg.y
  4. 3 2
      fifo_server.c
  5. 10 4
      flags.c
  6. 15 14
      forward.c
  7. 8 2
      ip_addr.c
  8. 2 2
      lock_alloc.h
  9. 20 18
      main.c
  10. 9 3
      name_alias.h
  11. 35 36
      proxy.c
  12. 8 9
      route.c
  13. 9 8
      route_struct.c
  14. 6 1
      script_cb.c
  15. 3 1
      sr_module.c
  16. 7 3
      timer.c
  17. 9 11
      udp_server.c

+ 5 - 3
action.c

@@ -30,6 +30,7 @@
  * 2003-01-29  removed scratchpad (jiri)
  * 2003-03-19  fixed set* len calculation bug & simplified a little the code
  *              (should be a little faster now) (andrei)
+ *             replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -142,7 +143,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				ret=forward_request(msg, p, proto);
 				/*free_uri(&uri); -- no longer needed, in sip_msg*/
 				free_proxy(p); /* frees only p content, not p itself */
-				free(p);
+				pkg_free(p);
 				if (ret>=0) ret=1;
 			}else if ((a->p1_type==PROXY_ST) && (a->p2_type==NUMBER_ST)){
 				ret=forward_request(msg,(struct proxy_l*)a->p1.data, proto);
@@ -161,7 +162,8 @@ int do_action(struct action* a, struct sip_msg* msg)
 				ret=E_BUG;
 				break;
 			}
-			to=(union sockaddr_union*) malloc(sizeof(union sockaddr_union));
+			to=(union sockaddr_union*)
+					pkg_malloc(sizeof(union sockaddr_union));
 			if (to==0){
 				LOG(L_ERR, "ERROR: do_action: "
 							"memory allocation failure\n");
@@ -199,7 +201,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				}
 #endif
 			}
-			free(to);
+			pkg_free(to);
 			if (ret<0){
 				p->errors++;
 				p->ok=0;

+ 7 - 8
cfg.lex

@@ -28,8 +28,9 @@
  *
  * History:
  * -------
- * 2001-01-29 src_port added (jiri)
- * 2001-01-23 mhomed added (jiri)
+ *  2003-01-29  src_port added (jiri)
+ *  2003-01-23  mhomed added (jiri)
+ *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -37,12 +38,10 @@
 	#include "cfg.tab.h"
 	#include "dprint.h"
 	#include "globals.h"
+	#include "mem/mem.h"
 	#include <string.h>
 	#include <stdlib.h>
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 	/* states */
 	#define INITIAL_S		0
@@ -330,7 +329,7 @@ EAT_ABLE	[\ \t\b\r]
 										case STRING_S: 
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
 														" unclosed string\n");
-											if (tstr) {free(tstr); tstr=0;}
+											if (tstr) {pkg_free(tstr);tstr=0;}
 											break;
 										case COMMENT_S:
 											LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
@@ -356,12 +355,12 @@ static char* addstr(char * src, char ** dest)
 	}else{
 		len1=strlen(*dest);
 		len2=strlen(src);
-		tmp=malloc(len1+len2+1);
+		tmp=pkg_malloc(len1+len2+1);
 		if (tmp==0) goto error;
 		memcpy(tmp, *dest, len1);
 		memcpy(tmp+len1, src, len2);
 		tmp[len1+len2]=0;
-		free(*dest);
+		pkg_free(*dest);
 		*dest=tmp;
 	}
 	return *dest;

+ 17 - 15
cfg.y

@@ -28,8 +28,9 @@
  *
  * History:
  * ---------
- * 2003-01-29 src_port added (jiri)
- * 2003-01-23 mhomed added (jiri)
+ * 2003-01-29  src_port added (jiri)
+ * 2003-01-23  mhomed added (jiri)
+ * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -222,7 +223,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 										"addresss.\n");
 								$$=0;
 							}else{
-								$$=malloc(strlen(tmp)+1);
+								$$=pkg_malloc(strlen(tmp)+1);
 								if ($$==0){
 									LOG(L_CRIT, "ERROR: cfg. parser: out of "
 											"memory.\n");
@@ -231,7 +232,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 								}
 							}
 						}
-		 |	ID			{	$$=malloc(strlen($1)+1);
+		 |	ID			{	$$=pkg_malloc(strlen($1)+1);
 		 					if ($$==0){
 									LOG(L_CRIT, "ERROR: cfg. parser: out of "
 											"memory.\n");
@@ -239,7 +240,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 									strncpy($$, $1, strlen($1)+1);
 							}
 						}
-		 |	STRING			{	$$=malloc(strlen($1)+1);
+		 |	STRING			{	$$=pkg_malloc(strlen($1)+1);
 		 					if ($$==0){
 									LOG(L_CRIT, "ERROR: cfg. parser: out of "
 											"memory.\n");
@@ -247,7 +248,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 									strncpy($$, $1, strlen($1)+1);
 							}
 						}
-		 |	host		{	$$=malloc(strlen($1)+1);
+		 |	host		{	$$=pkg_malloc(strlen($1)+1);
 		 					if ($$==0){
 									LOG(L_CRIT, "ERROR: cfg. parser: out of "
 											"memory.\n");
@@ -257,7 +258,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 						}
 	;
 
-id_lst:	  listen_id	{	$$=malloc(sizeof(struct id_list));
+id_lst:	  listen_id	{	$$=pkg_malloc(sizeof(struct id_list));
 						if ($$==0){
 							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
 						}else{
@@ -266,7 +267,7 @@ id_lst:	  listen_id	{	$$=malloc(sizeof(struct id_list));
 						}
 					}
 		| listen_id id_lst	{
-						$$=malloc(sizeof(struct id_list));
+						$$=pkg_malloc(sizeof(struct id_list));
 						if ($$==0){
 							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
 						}else{
@@ -328,8 +329,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| LISTEN EQUAL id_lst {
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
 								if (sock_no < MAX_LISTEN){
-									sock_info[sock_no].name.s=
-										(char*)malloc(strlen(lst_tmp->s)+1);
+									sock_info[sock_no].name.s=(char*)
+											pkg_malloc(strlen(lst_tmp->s)+1);
 									if (sock_info[sock_no].name.s==0){
 										LOG(L_CRIT, "ERROR: cfg. parser:"
 													" out of memory.\n");
@@ -386,7 +387,8 @@ ip:		 ipv4  { $$=$1; }
 		;
 
 ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER { 
-											$$=malloc(sizeof(struct ip_addr));
+											$$=pkg_malloc(
+													sizeof(struct ip_addr));
 											if ($$==0){
 												LOG(L_CRIT, "ERROR: cfg. "
 													"parser: out of memory.\n"
@@ -419,7 +421,7 @@ ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
 	;
 
 ipv6:	IPV6ADDR {
-					$$=malloc(sizeof(struct ip_addr));
+					$$=pkg_malloc(sizeof(struct ip_addr));
 					if ($$==0){
 						LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
 					}else{
@@ -611,7 +613,7 @@ ipnet:	ip SLASH ip	{ $$=mk_net($1, $3); }
 	;
 
 host:	ID				{ $$=$1; }
-	| host DOT ID		{ $$=(char*)malloc(strlen($1)+1+strlen($3)+1);
+	| host DOT ID		{ $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
 						  if ($$==0){
 						  	LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
 										" failure while parsing host\n");
@@ -621,9 +623,9 @@ host:	ID				{ $$=$1; }
 						  	memcpy($$+strlen($1)+1, $3, strlen($3));
 						  	$$[strlen($1)+1+strlen($3)]=0;
 						  }
-						  free($1); free($3);
+						  pkg_free($1); pkg_free($3);
 						}
-	| host DOT error { $$=0; free($1); yyerror("invalid hostname"); }
+	| host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
 	;
 
 

+ 3 - 2
fifo_server.c

@@ -53,7 +53,8 @@
  *
  * History:
  * --------
- * 2003-01-29 new built-in fifo commands: arg and pwd (jiri)
+ *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -117,7 +118,7 @@ int register_fifo_cmd(fifo_cmd f, char *cmd_name, void *param)
 		LOG(L_ERR, "ERROR: register_fifo_cmd: attempt to register synonyms\n");
 		return E_BUG;
 	}
-	new_cmd=malloc(sizeof(struct fifo_command));
+	new_cmd=pkg_malloc(sizeof(struct fifo_command));
 	if (new_cmd==0) {
 		LOG(L_ERR, "ERROR: register_fifo_cmd: out of mem\n");
 		return E_OUT_OF_MEM;

+ 10 - 4
flags.c

@@ -24,6 +24,11 @@
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 #include <limits.h>
@@ -75,11 +80,12 @@ static int fixup_t_flag(void** param, int param_no)
 	DBG("DEBUG: fixing flag: %s\n", (char *) (*param));
 
 	if (param_no!=1) {
-		LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be fixed\n");
+		LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be"
+					" fixed\n");
 		return E_BUG;
 	};
 
-	if ( !(code = malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
+	if ( !(code =pkg_malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
 
 	*code = 0;
 	c = *param;
@@ -121,14 +127,14 @@ static int fixup_t_flag(void** param, int param_no)
 	}
 
 	/* free string */
-	free( *param );
+	pkg_free( *param );
 	/* fix now */
 	*param = code;
 	
 	return 0;
 
 error:
-	free( code );
+	pkg_free( code );
 	return E_CFG;
 }
 

+ 15 - 14
forward.c

@@ -26,14 +26,15 @@
  *
  * History:
  * -------
- * 2001-??-??  created by andrei
- * ????-??-??  lots of changes by a lot of people
- * 2003-01-23  support for determination of outbound interface added :
- *              get_out_socket (jiri)
- * 2003-01-24  reply to rport support added, contributed by
- *              Maxim Sobolev <[email protected]> and modified by andrei
- * 2003-02-11  removed calls to upd_send & tcp_send & replaced them with
- *              calls to msg_send (andrei)
+ *  2001-??-??  created by andrei
+ *  ????-??-??  lots of changes by a lot of people
+ *  2003-01-23  support for determination of outbound interface added :
+ *               get_out_socket (jiri)
+ *  2003-01-24  reply to rport support added, contributed by
+ *               Maxim Sobolev <[email protected]> and modified by andrei
+ *  2003-02-11  removed calls to upd_send & tcp_send & replaced them with
+ *               calls to msg_send (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -249,7 +250,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
 	buf=0;
 	id=0;
 	
-	to=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
+	to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
 	if (to==0){
 		ser_error=E_OUT_OF_MEM;
 		LOG(L_ERR, "ERROR: forward_request: out of memory\n");
@@ -325,12 +326,12 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
 	STATS_TX_REQUEST(  msg->first_line.u.request.method_value );
 	
 	pkg_free(buf);
-	free(to);
+	pkg_free(to);
 	/* received_buf & line_buf will be freed in receive_msg by free_lump_list*/
 	return 0;
 
 error1:
-	free(to);
+	pkg_free(to);
 error:
 	if (buf) pkg_free(buf);
 	return -1;
@@ -435,7 +436,7 @@ int forward_reply(struct sip_msg* msg)
 		goto error;
 	}
 
-	to=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
+	to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
 	if (to==0){
 		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
 		goto error;
@@ -474,11 +475,11 @@ int forward_reply(struct sip_msg* msg)
 			(unsigned short) msg->via2->port);
 
 	pkg_free(new_buf);
-	free(to);
+	pkg_free(to);
 skip:
 	return 0;
 error:
 	if (new_buf) pkg_free(new_buf);
-	if (to) free(to);
+	if (to) pkg_free(to);
 	return -1;
 }

+ 8 - 2
ip_addr.c

@@ -27,6 +27,11 @@
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free
+ */
 
 
 #include <stdlib.h>
@@ -34,6 +39,7 @@
 
 #include "ip_addr.h"
 #include "dprint.h"
+#include "mem/mem.h"
 
 
 struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask)
@@ -45,7 +51,7 @@ struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask)
 				" (eg. ipv4/ipv6mask or ipv6/ipv4mask)\n");
 		goto error;
 	}
-	n=(struct net*)malloc(sizeof(struct net));
+	n=(struct net*)pkg_malloc(sizeof(struct net));
 	if (n==0){ 
 		LOG(L_CRIT, "ERROR: mk_net: memory allocation failure\n");
 		goto error;
@@ -68,7 +74,7 @@ struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen)
 		LOG(L_CRIT, "ERROR: mk_net_bitlen: bad bitlen number %d\n", bitlen);
 		goto error;
 	}
-	n=(struct net*)malloc(sizeof(struct net));
+	n=(struct net*)pkg_malloc(sizeof(struct net));
 	if (n==0){
 		LOG(L_CRIT, "ERROR: mk_net_bitlen: memory allocation failure\n"); 
 		goto error;

+ 2 - 2
lock_alloc.h

@@ -60,7 +60,7 @@ Implements: (see also locking.h)
 #if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
 /* simple locks*/
 #define lock_alloc() shm_malloc(sizeof(gen_lock_t))
-#define lock_dealloc(lock) shm_free(lock)
+#define lock_dealloc(lock) shm_free((void*)lock)
 /* lock sets */
 
 inline static lock_set_t* lock_set_alloc(int n)
@@ -82,7 +82,7 @@ inline static lock_set_t* lock_set_alloc(int n)
 
 /*simple locks*/
 #define lock_alloc() shm_malloc(sizeof(gen_lock_t))
-#define lock_dealloc(lock) shm_free(lock)
+#define lock_dealloc(lock) shm_free((void*)lock)
 /* lock sets */
 
 inline static lock_set_t* lock_set_alloc(int n)

+ 20 - 18
main.c

@@ -26,8 +26,9 @@
  *
  * History:
  * -------
- * 2002-01-29 argc/argv globalized via my_{argc|argv} (jiri)
- * 2001-01-23 mhomed added (jiri)
+ * 2002-01-29  argc/argv globalized via my_{argc|argv} (jiri)
+ * 2003-01-23  mhomed added (jiri)
+ * 2003-03-19  replaced all malloc/frees w/ pkg_malloc/pkg_free (andrei)
  *
  */
 
@@ -947,7 +948,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 	ifc.ifc_req=0;
 	for (size=10; ; size*=2){
 		ifc.ifc_len=size*sizeof(struct ifreq);
-		ifc.ifc_req=(struct ifreq*) malloc(size*sizeof(struct ifreq));
+		ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));
 		if (ifc.ifc_req==0){
 			fprintf(stderr, "memory allocation failure\n");
 			goto error;
@@ -961,7 +962,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 														   len not changed*/
 		lastlen=ifc.ifc_len;
 		/* try a bigger array*/
-		free(ifc.ifc_req);
+		pkg_free(ifc.ifc_req);
 	}
 	
 	last=(char*)ifc.ifc_req+ifc.ifc_len;
@@ -1008,7 +1009,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
 				if ((tmp=ip_addr2a(&addr))==0) goto error;
 				/* fill the strings*/
-				sock_info[sock_no].name.s=(char*)malloc(strlen(tmp)+1);
+				sock_info[sock_no].name.s=(char*)pkg_malloc(strlen(tmp)+1);
 				if(sock_info[sock_no].name.s==0){
 					fprintf(stderr, "Out of memory.\n");
 					goto error;
@@ -1036,11 +1037,11 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 			ls_ifflags(ifr->ifr_name, family, options);
 			printf("\n");*/
 	}
-	free(ifc.ifc_req); /*clean up*/
+	pkg_free(ifc.ifc_req); /*clean up*/
 	close(s);
 	return  ret;
 error:
-	if (ifc.ifc_req) free(ifc.ifc_req);
+	if (ifc.ifc_req) pkg_free(ifc.ifc_req);
 	close(s);
 	return -1;
 }
@@ -1159,7 +1160,7 @@ int main(int argc, char** argv)
 					/* add a new addr. to our address list */
 					if (sock_no < MAX_LISTEN){
 						sock_info[sock_no].name.s=
-										(char*)malloc(strlen(optarg)+1);
+										(char*)pkg_malloc(strlen(optarg)+1);
 						if (sock_info[sock_no].name.s==0){
 							fprintf(stderr, "Out of memory.\n");
 							goto error;
@@ -1377,7 +1378,8 @@ try_again:
 				fprintf(stderr, "cannot determine hostname, try -l address\n");
 				goto error;
 			}
-			sock_info[sock_no].name.s=(char*)malloc(strlen(myname.nodename)+1);
+			sock_info[sock_no].name.s=
+								(char*)pkg_malloc(strlen(myname.nodename)+1);
 			if (sock_info[sock_no].name.s==0){
 				fprintf(stderr, "Out of memory.\n");
 				goto error;
@@ -1395,7 +1397,7 @@ try_again:
 		if (add_interfaces(sock_info[r].name.s, AF_INET,
 					sock_info[r].port_no)!=-1){
 			/* success => remove current entry (shift the entire array)*/
-			free(sock_info[r].name.s);
+			pkg_free(sock_info[r].name.s);
 			memmove(&sock_info[r], &sock_info[r+1], 
 						(sock_no-r)*sizeof(struct socket_info));
 			sock_no--;
@@ -1427,7 +1429,7 @@ try_again:
 		  not have  enough space */
 		port_no_str_len=
 				(port_no_str_len<MAX_PORT_LEN)?port_no_str_len:MAX_PORT_LEN;
-		sock_info[r].port_no_str.s=(char*)malloc(strlen(port_no_str)+1);
+		sock_info[r].port_no_str.s=(char*)pkg_malloc(strlen(port_no_str)+1);
 		if (sock_info[r].port_no_str.s==0){
 			fprintf(stderr, "Out of memory.\n");
 			goto error;
@@ -1449,8 +1451,8 @@ try_again:
 				LOG(L_ERR, "ERROR: main: add_alias failed\n");
 			}
 			/* change the oficial name */
-			free(sock_info[r].name.s);
-			sock_info[r].name.s=(char*)malloc(strlen(he->h_name)+1);
+			pkg_free(sock_info[r].name.s);
+			sock_info[r].name.s=(char*)pkg_malloc(strlen(he->h_name)+1);
 			if (sock_info[r].name.s==0){
 				fprintf(stderr, "Out of memory.\n");
 				goto error;
@@ -1466,7 +1468,7 @@ try_again:
 		hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
 														 format*/
 		if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error;
-		sock_info[r].address_str.s=(char*)malloc(strlen(tmp)+1);
+		sock_info[r].address_str.s=(char*)pkg_malloc(strlen(tmp)+1);
 		if (sock_info[r].address_str.s==0){
 			fprintf(stderr, "Out of memory.\n");
 			goto error;
@@ -1527,9 +1529,9 @@ try_again:
 								sock_info[t].port_no);
 						
 				/* free space*/
-				free(sock_info[t].name.s);
-				free(sock_info[t].address_str.s);
-				free(sock_info[t].port_no_str.s);
+				pkg_free(sock_info[t].name.s);
+				pkg_free(sock_info[t].address_str.s);
+				pkg_free(sock_info[t].port_no_str.s);
 				/* shift the array*/
 				memmove(&sock_info[t], &sock_info[t+1], 
 							(sock_no-t)*sizeof(struct socket_info));
@@ -1575,7 +1577,7 @@ try_again:
 #ifdef SHM_MEM
 	pt=shm_malloc(sizeof(struct process_table)*process_count());
 #else
-	pt=malloc(sizeof(struct process_table)*process_count());
+	pt=pkg_malloc(sizeof(struct process_table)*process_count());
 #endif
 	if (pt==0){
 		fprintf(stderr, "ERROR: out  of memory\n");

+ 9 - 3
name_alias.h

@@ -25,11 +25,17 @@
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 
 #include "str.h"
 #include "dprint.h"
+#include "mem/mem.h"
 
 
 
@@ -68,9 +74,9 @@ static inline int add_alias(char* name, int len, unsigned short port)
 	
 	if ((port) && grep_aliases(name,len, port)) return 0;
 	a=0;
-	a=(struct host_alias*)malloc(sizeof(struct host_alias));
+	a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias));
 	if(a==0) goto error;
-	a->alias.s=(char*)malloc(len+1);
+	a->alias.s=(char*)pkg_malloc(len+1);
 	if (a->alias.s==0) goto error;
 	a->alias.len=len;
 	memcpy(a->alias.s, name, len);
@@ -81,7 +87,7 @@ static inline int add_alias(char* name, int len, unsigned short port)
 	return 1;
 error:
 	LOG(L_ERR, "ERROR: add_alias: memory allocation error\n");
-	if (a) free(a);
+	if (a) pkg_free(a);
 	return -1;
 }
 

+ 35 - 36
proxy.c

@@ -31,6 +31,7 @@
   * History:
   * -------
   *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
+  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
   */
 
 
@@ -39,6 +40,7 @@
 #include "proxy.h"
 #include "error.h"
 #include "dprint.h"
+#include "mem/mem.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -52,9 +54,6 @@
 #include "ip_addr.h"
 #include "globals.h"
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 struct proxy_l* proxies=0;
 
@@ -86,7 +85,7 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
 	/* start copying the host entry.. */
 	/* copy h_name */
 	len=strlen(src->h_name)+1;
-	dst->h_name=(char*)malloc(sizeof(char) * len);
+	dst->h_name=(char*)pkg_malloc(sizeof(char) * len);
 	if (dst->h_name) strncpy(dst->h_name,src->h_name, len);
 	else{
 		ser_error=ret=E_OUT_OF_MEM;
@@ -97,21 +96,21 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
 	len=0;
 	if (src->h_aliases)
 		for (;src->h_aliases[len];len++);
-	dst->h_aliases=(char**)malloc(sizeof(char*)*(len+1));
+	dst->h_aliases=(char**)pkg_malloc(sizeof(char*)*(len+1));
 	if (dst->h_aliases==0){
 		ser_error=ret=E_OUT_OF_MEM;
-		free(dst->h_name);
+		pkg_free(dst->h_name);
 		goto error;
 	}
 	memset((void*)dst->h_aliases, 0, sizeof(char*) * (len+1) );
 	for (i=0;i<len;i++){
 		len2=strlen(src->h_aliases[i])+1;
-		dst->h_aliases[i]=(char*)malloc(sizeof(char)*len2);
+		dst->h_aliases[i]=(char*)pkg_malloc(sizeof(char)*len2);
 		if (dst->h_aliases==0){
 			ser_error=ret=E_OUT_OF_MEM;
-			free(dst->h_name);
-			for(r=0; r<i; r++)	free(dst->h_aliases[r]);
-			free(dst->h_aliases);
+			pkg_free(dst->h_name);
+			for(r=0; r<i; r++)	pkg_free(dst->h_aliases[r]);
+			pkg_free(dst->h_aliases);
 			goto error;
 		}
 		strncpy(dst->h_aliases[i], src->h_aliases[i], len2);
@@ -120,26 +119,26 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
 	len=0;
 	if (src->h_addr_list)
 		for (;src->h_addr_list[len];len++);
-	dst->h_addr_list=(char**)malloc(sizeof(char*)*(len+1));
+	dst->h_addr_list=(char**)pkg_malloc(sizeof(char*)*(len+1));
 	if (dst->h_addr_list==0){
 		ser_error=ret=E_OUT_OF_MEM;
-		free(dst->h_name);
-		for(r=0; dst->h_aliases[r]; r++)	free(dst->h_aliases[r]);
-		free(dst->h_aliases[r]);
-		free(dst->h_aliases);
+		pkg_free(dst->h_name);
+		for(r=0; dst->h_aliases[r]; r++)	pkg_free(dst->h_aliases[r]);
+		pkg_free(dst->h_aliases[r]);
+		pkg_free(dst->h_aliases);
 		goto error;
 	}
 	memset((void*)dst->h_addr_list, 0, sizeof(char*) * (len+1) );
 	for (i=0;i<len;i++){
-		dst->h_addr_list[i]=(char*)malloc(sizeof(char)*src->h_length);
+		dst->h_addr_list[i]=(char*)pkg_malloc(sizeof(char)*src->h_length);
 		if (dst->h_addr_list[i]==0){
 			ser_error=ret=E_OUT_OF_MEM;
-			free(dst->h_name);
-			for(r=0; dst->h_aliases[r]; r++)	free(dst->h_aliases[r]);
-			free(dst->h_aliases[r]);
-			free(dst->h_aliases);
-			for (r=0; r<i;r++) free(dst->h_addr_list[r]);
-			free(dst->h_addr_list);
+			pkg_free(dst->h_name);
+			for(r=0; dst->h_aliases[r]; r++)	pkg_free(dst->h_aliases[r]);
+			pkg_free(dst->h_aliases[r]);
+			pkg_free(dst->h_aliases);
+			for (r=0; r<i;r++) pkg_free(dst->h_addr_list[r]);
+			pkg_free(dst->h_addr_list);
 			goto error;
 		}
 		memcpy(dst->h_addr_list[i], src->h_addr_list[i], src->h_length);
@@ -162,16 +161,16 @@ error:
 void free_hostent(struct hostent *dst)
 {
 	int r;
-	if (dst->h_name) free(dst->h_name);
+	if (dst->h_name) pkg_free(dst->h_name);
 	if (dst->h_aliases){
-		for(r=0; dst->h_aliases[r]; r++)	free(dst->h_aliases[r]);
-		free(dst->h_aliases[r]);
-		free(dst->h_aliases);
+		for(r=0; dst->h_aliases[r]; r++)	pkg_free(dst->h_aliases[r]);
+		pkg_free(dst->h_aliases[r]);
+		pkg_free(dst->h_aliases);
 	}
 	if (dst->h_addr_list){
-		for (r=0; dst->h_addr_list[r];r++) free(dst->h_addr_list[r]);
-		free(dst->h_addr_list[r]);
-		free(dst->h_addr_list);
+		for (r=0; dst->h_addr_list[r];r++) pkg_free(dst->h_addr_list[r]);
+		pkg_free(dst->h_addr_list[r]);
+		pkg_free(dst->h_addr_list);
 	}
 }
 
@@ -204,7 +203,7 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
 	struct proxy_l* p;
 	struct hostent* he;
 
-	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
+	p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
 	if (p==0){
 		ser_error=E_OUT_OF_MEM;
 		LOG(L_CRIT, "ERROR: mk_proxy: memory allocation failure\n");
@@ -221,11 +220,11 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
 		ser_error=E_BAD_ADDRESS;
 		LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
 					" \"%.*s\"\n", name->len, name->s);
-		free(p);
+		pkg_free(p);
 		goto error;
 	}
 	if (hostent_cpy(&(p->host), he)!=0){
-		free(p);
+		pkg_free(p);
 		goto error;
 	}
 	p->ok=1;
@@ -242,7 +241,7 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
 {
 	struct proxy_l* p;
 
-	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
+	p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
 	if (p==0){
 		LOG(L_CRIT, "ERROR: mk_proxy_from_ip: memory allocation failure\n");
 		goto error;
@@ -253,12 +252,12 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
 	p->proto=proto;
 	p->host.h_addrtype=ip->af;
 	p->host.h_length=ip->len;
-	p->host.h_addr_list=malloc(2*sizeof(char*));
+	p->host.h_addr_list=pkg_malloc(2*sizeof(char*));
 	if (p->host.h_addr_list==0) goto error;
 	p->host.h_addr_list[1]=0;
-	p->host.h_addr_list[0]=malloc(ip->len+1);
+	p->host.h_addr_list[0]=pkg_malloc(ip->len+1);
 	if (p->host.h_addr_list[0]==0){
-		free(p->host.h_addr_list);
+		pkg_free(p->host.h_addr_list);
 		goto error;
 	}
 

+ 8 - 9
route.c

@@ -29,9 +29,10 @@
  *
  * History:
  * --------
- * 2003-02-28  scratchpad compatibility abandoned (jiri)
- * 2003-01-28  scratchpad removed, src_port introduced (jiri)
- * 2003-03-10  updated to the new module exports format (andrei)
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
+ *  2003-01-28  scratchpad removed, src_port introduced (jiri)
+ *  2003-03-10  updated to the new module exports format (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
  
@@ -54,10 +55,8 @@
 #include "ip_addr.h"
 #include "resolve.h"
 #include "parser/parse_uri.h"
+#include "mem/mem.h"
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 /* main routing script table  */
 struct action* rlist[RT_NO];
@@ -98,7 +97,7 @@ static int fix_expr(struct expr* exp)
 	}else if (exp->type==ELEM_T){
 			if (exp->op==MATCH_OP){
 				if (exp->subtype==STRING_ST){
-					re=(regex_t*)malloc(sizeof(regex_t));
+					re=(regex_t*)pkg_malloc(sizeof(regex_t));
 					if (re==0){
 						LOG(L_CRIT, "ERROR: fix_expr: memory allocation"
 								" failure\n");
@@ -108,11 +107,11 @@ static int fix_expr(struct expr* exp)
 								REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
 						LOG(L_CRIT, "ERROR: fix_expr : bad re \"%s\"\n",
 									(char*) exp->r.param);
-						free(re);
+						pkg_free(re);
 						return E_BAD_RE;
 					}
 					/* replace the string with the re */
-					free(exp->r.param);
+					pkg_free(exp->r.param);
 					exp->r.param=re;
 					exp->subtype=RE_ST;
 				}else if (exp->subtype!=RE_ST){

+ 9 - 8
route_struct.c

@@ -25,8 +25,11 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * 2003-01-29 src_port introduced (jiri)
+ */
+/* History:
+ * --------
+ *  2003-01-29  src_port introduced (jiri)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -39,15 +42,13 @@
 
 #include "dprint.h"
 #include "ip_addr.h"
+#include "mem/mem.h"
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)
 {
 	struct expr * e;
-	e=(struct expr*)malloc(sizeof (struct expr));
+	e=(struct expr*)pkg_malloc(sizeof (struct expr));
 	if (e==0) goto error;
 	e->type=EXP_T;
 	e->op=op;
@@ -63,7 +64,7 @@ error:
 struct expr* mk_elem(int op, int subtype, int operand, void* param)
 {
 	struct expr * e;
-	e=(struct expr*)malloc(sizeof (struct expr));
+	e=(struct expr*)pkg_malloc(sizeof (struct expr));
 	if (e==0) goto error;
 	e->type=ELEM_T;
 	e->op=op;
@@ -82,7 +83,7 @@ struct action* mk_action(int type, int p1_type, int p2_type,
 											void* p1, void* p2)
 {
 	struct action* a;
-	a=(struct action*)malloc(sizeof(struct action));
+	a=(struct action*)pkg_malloc(sizeof(struct action));
 	if (a==0) goto  error;
 	memset(a,0,sizeof(struct action));
 	a->type=type;

+ 6 - 1
script_cb.c

@@ -29,12 +29,17 @@
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/* History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 #include <stdlib.h>
 #include "script_cb.h"
 #include "dprint.h"
 #include "error.h"
+#include "mem/mem.h"
 
 static struct script_cb *pre_cb=0;
 static struct script_cb *post_cb=0;
@@ -44,7 +49,7 @@ int register_script_cb( cb_function f, callback_t t, void *param )
 {
 	struct script_cb *new_cb;
 
-	new_cb=malloc(sizeof(struct script_cb));
+	new_cb=pkg_malloc(sizeof(struct script_cb));
 	if (new_cb==0) {
 		LOG(L_ERR, "ERROR: register_script_cb: out of memory\n");
 		return E_OUT_OF_MEM;

+ 3 - 1
sr_module.c

@@ -28,12 +28,14 @@
  * --------
  *  2003-03-10  switched to new module_exports format: updated find_export,
  *               find_export_param, find_module (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
 #include "sr_module.h"
 #include "dprint.h"
 #include "error.h"
+#include "mem/mem.h"
 
 #include <dlfcn.h>
 #include <strings.h>
@@ -127,7 +129,7 @@ int register_module(struct module_exports* e, char* path, void* handle)
 	ret=-1;
 
 	/* add module to the list */
-	if ((mod=malloc(sizeof(struct sr_module)))==0){
+	if ((mod=pkg_malloc(sizeof(struct sr_module)))==0){
 		LOG(L_ERR, "load_module: memory allocation failure\n");
 		ret=E_OUT_OF_MEM;
 		goto error;

+ 7 - 3
timer.c

@@ -24,6 +24,10 @@
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/* History:
+ * --------
+ *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 #include "timer.h"
@@ -54,7 +58,7 @@ int init_timer()
 	/* in this case get_ticks won't work! */
 	LOG(L_INFO, "WARNING: no shared memory support compiled in"
 				" get_ticks won't work\n");
-	jiffies=malloc(sizeof(int));
+	jiffies=pkg_malloc(sizeof(int));
 #endif
 	if (jiffies==0){
 		LOG(L_CRIT, "ERROR: init_timer: could not init jiffies\n");
@@ -72,7 +76,7 @@ void destroy_timer()
 #ifdef SHM_MEM
 		shm_free(jiffies); jiffies=0;
 #else
-		free(jiffies); jiffies=0;
+		pkg_free(jiffies); jiffies=0;
 #endif
 	}
 }
@@ -85,7 +89,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
 {
 	struct sr_timer* t;
 
-	t=malloc(sizeof(struct sr_timer));
+	t=pkg_malloc(sizeof(struct sr_timer));
 	if (t==0){
 		LOG(L_ERR, "ERROR: register_timer: out of memory\n");
 		goto error;

+ 9 - 11
udp_server.c

@@ -26,8 +26,9 @@
  *
  * History
  * --------
- * 2003-01-28 packet zero-termination moved to receive_msg (jiri)
- * 2003-02-10 undoed the above changes (andrei)
+ *  2003-01-28  packet zero-termination moved to receive_msg (jiri)
+ *  2003-02-10  undoed the above changes (andrei)
+ *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -52,9 +53,6 @@
 #include "mem/mem.h"
 #include "ip_addr.h"
 
-#ifdef DEBUG_DMALLOC
-#include <mem/dmalloc.h>
-#endif
 
 #ifdef DBG_MSG_QA
 /* message quality assurance -- frequently, bugs in ser have
@@ -212,7 +210,7 @@ int udp_init(struct socket_info* sock_info)
 
 	addr=&sock_info->su;
 /*
-	addr=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
+	addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
 	if (addr==0){
 		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
 		goto error;
@@ -263,11 +261,11 @@ int udp_init(struct socket_info* sock_info)
 		goto error;
 	}
 
-/*	free(addr);*/
+/*	pkg_free(addr);*/
 	return 0;
 
 error:
-/*	if (addr) free(addr);*/
+/*	if (addr) pkg_free(addr);*/
 	return -1;
 }
 
@@ -287,7 +285,7 @@ int udp_rcv_loop()
 	struct receive_info ri;
 
 
-	from=(union sockaddr_union*) malloc(sizeof(union sockaddr_union));
+	from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
 	if (from==0){
 		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
 		goto error;
@@ -350,12 +348,12 @@ int udp_rcv_loop()
 		
 	}
 	/*
-	if (from) free(from);
+	if (from) pkg_free(from);
 	return 0;
 	*/
 	
 error:
-	if (from) free(from);
+	if (from) pkg_free(from);
 	return -1;
 }