Răsfoiți Sursa

- fixed almost all warnings in ser core (gcc-3.0 -Wall, icc, sun cc).
(=> fixed a lot of format string bugs)
- replaced some of the remaining mallocs w/ pkg_malloc

Andrei Pelinescu-Onciul 23 ani în urmă
părinte
comite
e22bbdb8e1
28 a modificat fișierele cu 130 adăugiri și 102 ștergeri
  1. 1 1
      Makefile.defs
  2. 1 1
      Makefile.rules
  3. 4 3
      action.c
  4. 1 0
      cfg.y
  5. 1 0
      data_lump.c
  6. 3 3
      data_lump_rpl.c
  7. 2 2
      data_lump_rpl.h
  8. 6 11
      forward.c
  9. 2 2
      main.c
  10. 2 0
      md5.c
  11. 1 1
      md5utils.c
  12. 3 2
      mem/f_malloc.c
  13. 9 5
      mem/mem.c
  14. 3 2
      mem/shm_mem.c
  15. 3 3
      modules/tm/t_fwd.c
  16. 3 3
      modules/tm/t_reply.c
  17. 4 2
      msg_parser.c
  18. 15 11
      msg_translator.c
  19. 0 1
      parse_hname.c
  20. 11 4
      parse_to.c
  21. 12 13
      parse_via.c
  22. 0 3
      proxy.c
  23. 4 3
      receive.c
  24. 0 2
      route.c
  25. 1 0
      route_struct.c
  26. 19 7
      sr_module.c
  27. 16 16
      udp_server.c
  28. 3 1
      ut.h

+ 1 - 1
Makefile.defs

@@ -171,7 +171,7 @@ ifeq	($(ARCH), i386)
 ifeq		($(CC_NAME), gcc)
 ifeq		($(CC_NAME), gcc)
 				#common stuff
 				#common stuff
 				CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) -Winline\
 				CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) -Winline\
-					#-Wmissing-prototypes \
+					-Wall #-Wmissing-prototypes \
 			#if gcc 3.0
 			#if gcc 3.0
 ifeq			($(CC_SHORTVER), 3.0)
 ifeq			($(CC_SHORTVER), 3.0)
 					CFLAGS+=-minline-all-stringops -malign-double \
 					CFLAGS+=-minline-all-stringops -malign-double \

+ 1 - 1
Makefile.rules

@@ -39,7 +39,7 @@ static: $(objs)
 
 
 .PHONY: clean
 .PHONY: clean
 clean:
 clean:
-	-@rm -f $(objs) $(NAME) 2>/dev/null
+	-@rm -f $(objs) $(NAME) $(objs:.o=.il) 2>/dev/null
 	-@for r in $(modules) $(static_modules_path) "" ; do \
 	-@for r in $(modules) $(static_modules_path) "" ; do \
 		if [ -n "$$r" ]; then \
 		if [ -n "$$r" ]; then \
 			echo "module $$r" ; \
 			echo "module $$r" ; \

+ 4 - 3
action.c

@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <netinet/in.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/inet.h>
+#include <string.h>
 
 
 #ifdef DEBUG_DMALLOC
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
 #include <dmalloc.h>
@@ -77,7 +78,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 										if (err){
 										if (err){
 											LOG(L_ERR, "ERROR: do_action: "
 											LOG(L_ERR, "ERROR: do_action: "
 													"forward: bad port in "
 													"forward: bad port in "
-													"uri: <%s>\n", uri.port);
+													"uri: <%s>\n", uri.port.s);
 											ret=E_UNSPEC;
 											ret=E_UNSPEC;
 											goto error_fwd_uri;
 											goto error_fwd_uri;
 										}
 										}
@@ -369,7 +370,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 		default:
 		default:
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
 	}
 	}
-skip:
+/*skip:*/
 	return ret;
 	return ret;
 	
 	
 error_uri:
 error_uri:
@@ -389,7 +390,7 @@ error_fwd_uri:
 int run_actions(struct action* a, struct sip_msg* msg)
 int run_actions(struct action* a, struct sip_msg* msg)
 {
 {
 	struct action* t;
 	struct action* t;
-	int ret;
+	int ret=E_UNSPEC;
 	static int rec_lev=0;
 	static int rec_lev=0;
 	struct sr_module *mod;
 	struct sr_module *mod;
 
 

+ 1 - 0
cfg.y

@@ -24,6 +24,7 @@
 #include <dmalloc.h>
 #include <dmalloc.h>
 #endif
 #endif
 
 
+extern int yylex();
 void yyerror(char* s);
 void yyerror(char* s);
 char* tmp;
 char* tmp;
 void* f_tmp;
 void* f_tmp;

+ 1 - 0
data_lump.c

@@ -7,6 +7,7 @@
 #include "mem/mem.h"
 #include "mem/mem.h"
 
 
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 
 
 #ifdef DEBUG_DMALLOC
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
 #include <dmalloc.h>

+ 3 - 3
data_lump_rpl.c

@@ -1,5 +1,5 @@
 
 
-
+#include <string.h>
 #include "dprint.h"
 #include "dprint.h"
 #include "mem/mem.h"
 #include "mem/mem.h"
 #include "data_lump_rpl.h"
 #include "data_lump_rpl.h"
@@ -36,7 +36,7 @@ error:
 
 
 
 
 
 
-int add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
+void add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
 {
 {
 	struct lump_rpl *foo;
 	struct lump_rpl *foo;
 
 
@@ -51,7 +51,7 @@ int add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
 
 
 
 
 
 
-int free_lump_rpl(struct lump_rpl* lump)
+void free_lump_rpl(struct lump_rpl* lump)
 {
 {
 	if (lump && lump->text.s)  pkg_free(lump->text.s);
 	if (lump && lump->text.s)  pkg_free(lump->text.s);
 	if (lump) pkg_free(lump);
 	if (lump) pkg_free(lump);

+ 2 - 2
data_lump_rpl.h

@@ -17,8 +17,8 @@ struct lump_rpl
 
 
 struct lump_rpl* build_lump_rpl( char* , int );
 struct lump_rpl* build_lump_rpl( char* , int );
 
 
-int add_lump_rpl(struct sip_msg * , struct lump_rpl* );
+void add_lump_rpl(struct sip_msg * , struct lump_rpl* );
 
 
-int free_lump_rpl(struct lump_rpl* );
+void free_lump_rpl(struct lump_rpl* );
 
 
 #endif
 #endif

+ 6 - 11
forward.c

@@ -82,12 +82,12 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 	}
 	}
 	/* sent requests stats */
 	/* sent requests stats */
 	else STATS_TX_REQUEST(  msg->first_line.u.request.method_value );
 	else STATS_TX_REQUEST(  msg->first_line.u.request.method_value );
-	free(buf);
+	pkg_free(buf);
 	free(to);
 	free(to);
 	/* received_buf & line_buf will be freed in receiv_msg by free_lump_list*/
 	/* received_buf & line_buf will be freed in receiv_msg by free_lump_list*/
 	return 0;
 	return 0;
 error:
 error:
-	if (buf) free(buf);
+	if (buf) pkg_free(buf);
 	if (to) free(to);
 	if (to) free(to);
 	return -1;
 	return -1;
 }
 }
@@ -131,12 +131,7 @@ int forward_reply(struct sip_msg* msg)
 	struct sockaddr_in* to;
 	struct sockaddr_in* to;
 	unsigned int new_len;
 	unsigned int new_len;
 	struct sr_module *mod;
 	struct sr_module *mod;
-#ifdef DNS_IP_HACK
-	int err;
-#endif
-
-
-
+	
 	to=0;
 	to=0;
 	new_buf=0;
 	new_buf=0;
 	/*check if first via host = us */
 	/*check if first via host = us */
@@ -145,7 +140,7 @@ int forward_reply(struct sip_msg* msg)
 			if(strcmp(msg->via1->host.s, names[r])==0) break;
 			if(strcmp(msg->via1->host.s, names[r])==0) break;
 		if (r==addresses_no){
 		if (r==addresses_no){
 			LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :"
 			LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :"
-					" %s\n", msg->via1->host);
+					" %s\n", msg->via1->host.s);
 			/* send error msg back? */
 			/* send error msg back? */
 			goto error;
 			goto error;
 		}
 		}
@@ -198,12 +193,12 @@ int forward_reply(struct sip_msg* msg)
 	DBG(" reply forwarded to %s:%d\n",msg->via2->host.s,
 	DBG(" reply forwarded to %s:%d\n",msg->via2->host.s,
 		(unsigned short) msg->via2->port);
 		(unsigned short) msg->via2->port);
 
 
-	free(new_buf);
+	pkg_free(new_buf);
 	free(to);
 	free(to);
 skip:
 skip:
 	return 0;
 	return 0;
 error:
 error:
-	if (new_buf) free(new_buf);
+	if (new_buf) pkg_free(new_buf);
 	if (to) free(to);
 	if (to) free(to);
 	return -1;
 	return -1;
 }
 }

+ 2 - 2
main.c

@@ -591,8 +591,8 @@ int main(int argc, char** argv)
 					printf("flags: %s\n", flags );
 					printf("flags: %s\n", flags );
 					print_ct_constants();
 					print_ct_constants();
 					printf("%s\n",id);
 					printf("%s\n",id);
-					printf("%s compiled on %s at %s with %s\n", __FILE__,
-							__DATE__, __TIME__, COMPILER );
+					printf("%s compiled on %s with %s\n", __FILE__,
+							compiled, COMPILER );
 					
 					
 					exit(0);
 					exit(0);
 					break;
 					break;

+ 2 - 0
md5.c

@@ -23,9 +23,11 @@ These notices must be retained in any copies of any part of this
 documentation and/or software.
 documentation and/or software.
  */
  */
 
 
+#include <string.h>
 #include "md5global.h"
 #include "md5global.h"
 #include "md5.h"
 #include "md5.h"
 
 
+
 #define USE_MEM
 #define USE_MEM
 
 
 /* Constants for MD5Transform routine.
 /* Constants for MD5Transform routine.

+ 1 - 1
md5utils.c

@@ -32,7 +32,7 @@ jku: added support to deal with vectors
 #include "ut.h"
 #include "ut.h"
 
 
 
 
-static void MDString PROTO_LIST ((char *));
+/*static void MDString PROTO_LIST ((char *));*/
 
 
 #define MD_CTX MD5_CTX
 #define MD_CTX MD5_CTX
 #define MDInit MD5Init
 #define MDInit MD5Init

+ 3 - 2
mem/f_malloc.c

@@ -4,6 +4,8 @@
 
 
 #if !defined(q_malloc) && !(defined VQ_MALLOC) 
 #if !defined(q_malloc) && !(defined VQ_MALLOC) 
 
 
+#include <string.h>
+
 #include "f_malloc.h"
 #include "f_malloc.h"
 #include "../dprint.h"
 #include "../dprint.h"
 
 
@@ -87,7 +89,6 @@ struct fm_block* fm_malloc_init(char* address, unsigned int size)
 	char* end;
 	char* end;
 	struct fm_block* qm;
 	struct fm_block* qm;
 	unsigned int init_overhead;
 	unsigned int init_overhead;
-	int h;
 	
 	
 	/* make address and size multiple of 8*/
 	/* make address and size multiple of 8*/
 	start=(char*)ROUNDUP((unsigned int) address);
 	start=(char*)ROUNDUP((unsigned int) address);
@@ -261,7 +262,7 @@ void fm_status(struct fm_block* qm)
 	int h;
 	int h;
 	int size;
 	int size;
 
 
-	LOG(L_INFO, "fm_status (%x):\n", qm);
+	LOG(L_INFO, "fm_status (%p):\n", qm);
 	if (!qm) return;
 	if (!qm) return;
 
 
 	LOG(L_INFO, " heap size= %d\n", qm->size);
 	LOG(L_INFO, " heap size= %d\n", qm->size);

+ 9 - 5
mem/mem.c

@@ -7,11 +7,15 @@
 #include "mem.h"
 #include "mem.h"
 
 
 #ifdef PKG_MALLOC
 #ifdef PKG_MALLOC
-#	ifdef VQ_MALLOC
-#		include "vq_malloc.h"
-#	else
-#		include "q_malloc.h"
-#	endif
+	#ifdef VQ_MALLOC
+		#include "vq_malloc.h"
+	#else
+		#include "q_malloc.h"
+	#endif
+#endif
+
+#ifdef SHM_MEM
+#include "shm_mem.h"
 #endif
 #endif
 
 
 #ifdef PKG_MALLOC
 #ifdef PKG_MALLOC

+ 3 - 2
mem/shm_mem.c

@@ -82,7 +82,7 @@ void* _shm_resize( void* p, unsigned int s, char* file, char* func, unsigned int
 void* _shm_resize( void* p , unsigned int s)
 void* _shm_resize( void* p , unsigned int s)
 #endif
 #endif
 {
 {
-	char *c;
+	
 #ifdef VQ_MALLOC
 #ifdef VQ_MALLOC
 	struct vqm_frag *f;
 	struct vqm_frag *f;
 #else
 #else
@@ -125,13 +125,14 @@ void* _shm_resize( void* p , unsigned int s)
 int shm_mem_init()
 int shm_mem_init()
 {
 {
 
 
+#ifndef FAST_LOCK
 	union semun su;
 	union semun su;
+#endif
 #ifdef SHM_MMAP
 #ifdef SHM_MMAP
 	int fd;
 	int fd;
 #else
 #else
 	struct shmid_ds shm_info;
 	struct shmid_ds shm_info;
 #endif
 #endif
-	int ret;
 
 
 #ifdef SHM_MMAP
 #ifdef SHM_MMAP
 	if (shm_mempool && (shm_mempool!=(void*)-1)){
 	if (shm_mempool && (shm_mempool!=(void*)-1)){

+ 3 - 3
modules/tm/t_fwd.c

@@ -112,7 +112,7 @@ int t_forward_nonack( struct sip_msg* p_msg , unsigned int dest_ip_param ,
 		T->outbound_request[branch] = rb;
 		T->outbound_request[branch] = rb;
 		SEND_BUFFER( rb );
 		SEND_BUFFER( rb );
 		/* link the retransmission buffer to our structures when the job is done */
 		/* link the retransmission buffer to our structures when the job is done */
-		free( buf ) ; buf=NULL;
+		pkg_free( buf ) ; buf=NULL;
 
 
 		DBG("DEBUG: t_forward_nonack: starting timers (retrans and FR) %d\n",get_ticks() );
 		DBG("DEBUG: t_forward_nonack: starting timers (retrans and FR) %d\n",get_ticks() );
 		/*sets and starts the FINAL RESPONSE timer */
 		/*sets and starts the FINAL RESPONSE timer */
@@ -154,7 +154,7 @@ error:
 		shm_free(rb);
 		shm_free(rb);
 		T->outbound_request[branch]=NULL;
 		T->outbound_request[branch]=NULL;
 	}
 	}
-	if (buf) free( buf );
+	if (buf) pkg_free( buf );
 
 
 	return -1;
 	return -1;
 
 
@@ -222,7 +222,7 @@ int t_forward_ack( struct sip_msg* p_msg , unsigned int dest_ip_param ,
 	shm_unlock();
 	shm_unlock();
 
 
 	memcpy( (char *) srb + sizeof ( struct retrans_buff ), buf, len );
 	memcpy( (char *) srb + sizeof ( struct retrans_buff ), buf, len );
-	free( buf );
+	pkg_free( buf );
 
 
 	relay_ack( T, branch, srb, len );
 	relay_ack( T, branch, srb, len );
 	return 1;
 	return 1;

+ 3 - 3
modules/tm/t_reply.c

@@ -106,7 +106,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
 
 
 	SEND_PR_BUFFER( rb, buf, len );
 	SEND_PR_BUFFER( rb, buf, len );
 
 
-	free( buf ) ;
+	pkg_free( buf ) ;
 	/* start/stops the proper timers*/
 	/* start/stops the proper timers*/
 
 
 	DBG("DEBUG: t_send_reply: finished\n");
 	DBG("DEBUG: t_send_reply: finished\n");
@@ -114,7 +114,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
 	return 1;
 	return 1;
 
 
 error2:
 error2:
-	free ( buf );
+	pkg_free ( buf );
 error:
 error:
 	return -1;
 	return -1;
 }
 }
@@ -385,7 +385,7 @@ cleanup:
 error2:
 error2:
 	if (start_fr) 
 	if (start_fr) 
 		set_timer( hash_table, &(orq_rb->fr_timer), FR_INV_TIMER_LIST );
 		set_timer( hash_table, &(orq_rb->fr_timer), FR_INV_TIMER_LIST );
-	if (buf) free( buf );
+	if (buf) pkg_free( buf );
 error1:
 error1:
 	if (!save_clone) sip_msg_free( clone );
 	if (!save_clone) sip_msg_free( clone );
 error:
 error:

+ 4 - 2
msg_parser.c

@@ -174,9 +174,10 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 error:
 error:
 	LOG(L_INFO, "ERROR:parse_first_line: bad %s first line\n",
 	LOG(L_INFO, "ERROR:parse_first_line: bad %s first line\n",
 		(fl->type==SIP_REPLY)?"reply(status)":"request");
 		(fl->type==SIP_REPLY)?"reply(status)":"request");
+	LOG(L_INFO, "ERROR: at line 0 char %d\n", offset);
 error1:
 error1:
 	fl->type=SIP_INVALID;
 	fl->type=SIP_INVALID;
-	LOG(L_INFO, "ERROR: at line 0 char %d\n", offset);
+	LOG(L_INFO, "ERROR:parse_first_line: bad message\n");
 	/* skip  line */
 	/* skip  line */
 	nl=eat_line(buffer,len);
 	nl=eat_line(buffer,len);
 	return nl;
 	return nl;
@@ -677,7 +678,7 @@ error:
 int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 {
 {
 
 
-	char *tmp, *bar;
+	char *tmp;
 	char* rest;
 	char* rest;
 	char* first_via;
 	char* first_via;
 	char* second_via;
 	char* second_via;
@@ -717,6 +718,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 			break;
 			break;
 		default:
 		default:
 			DBG("unknown type %d\n",fl->type);
 			DBG("unknown type %d\n",fl->type);
+			goto error;
 	}
 	}
 	msg->unparsed=tmp;
 	msg->unparsed=tmp;
 	/*find first Via: */
 	/*find first Via: */

+ 15 - 11
msg_translator.c

@@ -4,6 +4,8 @@
 
 
 
 
 #include <sys/socket.h>
 #include <sys/socket.h>
+#include <netdb.h>
+#include <string.h>
 
 
 #include "msg_translator.h"
 #include "msg_translator.h"
 #include "mem/mem.h"
 #include "mem/mem.h"
@@ -11,13 +13,16 @@
 #include "config.h"
 #include "config.h"
 #include "md5utils.h"
 #include "md5utils.h"
 #include "data_lump_rpl.h"
 #include "data_lump_rpl.h"
-#include <netdb.h>
 
 
 
 
 
 
 #define MAX_VIA_LINE_SIZE      240
 #define MAX_VIA_LINE_SIZE      240
 #define MAX_RECEIVED_SIZE  57
 #define MAX_RECEIVED_SIZE  57
 
 
+/* mallocs for local stuff (not needed to be shared mem?)*/
+#define local_malloc pkg_malloc
+#define local_free   pkg_free
+
 
 
 #define append_str(_dest,_src,_len,_msg) \
 #define append_str(_dest,_src,_len,_msg) \
 	do{\
 	do{\
@@ -114,7 +119,6 @@ int check_address(unsigned long ip, char *name, int resolver)
 	}
 	}
 	if (resolver&DO_REV_DNS){
 	if (resolver&DO_REV_DNS){
 		DBG("check_address: doing rev. dns lookup\n");
 		DBG("check_address: doing rev. dns lookup\n");
-		print_ip(ip);
 		/* try reverse dns */
 		/* try reverse dns */
 		he=gethostbyaddr((char*)&ip, sizeof(ip), AF_INET);
 		he=gethostbyaddr((char*)&ip, sizeof(ip), AF_INET);
 		if (he && (strcmp(he->h_name, name)==0))
 		if (he && (strcmp(he->h_name, name)==0))
@@ -232,6 +236,7 @@ char * build_req_buf_from_sip_req(	struct sip_msg* msg,
 	struct lump *t,*r;
 	struct lump *t,*r;
 	struct lump* anchor;
 	struct lump* anchor;
 
 
+	uri_len=0;
 	orig=msg->orig;
 	orig=msg->orig;
 	buf=msg->buf;
 	buf=msg->buf;
 	len=msg->len;
 	len=msg->len;
@@ -332,7 +337,7 @@ char * build_req_buf_from_sip_req(	struct sip_msg* msg,
 					s_offset=t->u.offset;
 					s_offset=t->u.offset;
 				/* do nothing */
 				/* do nothing */
 				break;
 				break;
-			debug:
+			default:
 				LOG(L_CRIT,"BUG:build_req_buf_from_sip_req: invalid"
 				LOG(L_CRIT,"BUG:build_req_buf_from_sip_req: invalid"
 							" op for data lump (%x)\n", r->op);
 							" op for data lump (%x)\n", r->op);
 		}
 		}
@@ -354,7 +359,7 @@ char * build_req_buf_from_sip_req(	struct sip_msg* msg,
 		uri_len=msg->new_uri.len;
 		uri_len=msg->new_uri.len;
 		new_len=new_len-msg->first_line.u.request.uri.len+uri_len;
 		new_len=new_len-msg->first_line.u.request.uri.len+uri_len;
 	}
 	}
-	new_buf=(char*)malloc(new_len+1);
+	new_buf=(char*)local_malloc(new_len+1);
 	if (new_buf==0){
 	if (new_buf==0){
 		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: out of memory\n");
 		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: out of memory\n");
 		goto error;
 		goto error;
@@ -477,7 +482,7 @@ error1:
 	if (received_buf) pkg_free(received_buf);
 	if (received_buf) pkg_free(received_buf);
 	if (line_buf) pkg_free(line_buf);
 	if (line_buf) pkg_free(line_buf);
 error:
 error:
-	if (new_buf) free(new_buf);
+	if (new_buf) local_free(new_buf);
 	*returned_len=0;
 	*returned_len=0;
 	return 0;
 	return 0;
 }
 }
@@ -488,10 +493,9 @@ error:
 char * build_res_buf_from_sip_res( struct sip_msg* msg,
 char * build_res_buf_from_sip_res( struct sip_msg* msg,
 				unsigned int *returned_len)
 				unsigned int *returned_len)
 {
 {
-	unsigned int new_len, via_len,r;
+	unsigned int new_len, via_len;
 	char* new_buf;
 	char* new_buf;
 	unsigned offset, s_offset, size;
 	unsigned offset, s_offset, size;
-	struct hostent* he;
 	char* orig;
 	char* orig;
 	char* buf;
 	char* buf;
 	unsigned int len;
 	unsigned int len;
@@ -516,7 +520,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
 	new_len=len-via_len;
 	new_len=len-via_len;
 
 
 	DBG(" old size: %d, new size: %d\n", len, new_len);
 	DBG(" old size: %d, new size: %d\n", len, new_len);
-	new_buf=(char*)malloc(new_len+1);/* +1 is for debugging
+	new_buf=(char*)local_malloc(new_len+1);/* +1 is for debugging
 											(\0 to print it )*/
 											(\0 to print it )*/
 	if (new_buf==0){
 	if (new_buf==0){
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_res: out of memory\n");
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_res: out of memory\n");
@@ -535,7 +539,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
 	*returned_len=new_len;
 	*returned_len=new_len;
 	return new_buf;
 	return new_buf;
 error:
 error:
-	if (new_buf) free(new_buf);
+	if (new_buf) local_free(new_buf);
 	*returned_len=0;
 	*returned_len=0;
 	return 0;
 	return 0;
 }
 }
@@ -596,7 +600,7 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 	len += CRLF_LEN; /*new line*/
 	len += CRLF_LEN; /*new line*/
 	/*allocating mem*/
 	/*allocating mem*/
 	buf = 0;
 	buf = 0;
-	buf = (char*) malloc( len+1 );
+	buf = (char*) local_malloc( len+1 );
 	if (!buf)
 	if (!buf)
 	{
 	{
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: out of memory "
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: out of memory "
@@ -677,7 +681,7 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 	*returned_len = len;
 	*returned_len = len;
 	return buf;
 	return buf;
 error:
 error:
-	if (buf) free(buf);
+	if (buf) local_free(buf);
 	*returned_len=0;
 	*returned_len=0;
 	return 0;
 	return 0;
 }
 }

+ 0 - 1
parse_hname.c

@@ -50,7 +50,6 @@ char* parse_hname1(char* p, char* end, struct hdr_field* hdr)
 
 
 	char* t;
 	char* t;
 	register int state;
 	register int state;
-	int i;
 	int err;
 	int err;
 	err=0;
 	err=0;
 
 

+ 11 - 4
parse_to.c

@@ -1,6 +1,7 @@
 
 
 
 
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 #include "dprint.h"
 #include "dprint.h"
 #include "msg_parser.h"
 #include "msg_parser.h"
 #include "ut.h"
 #include "ut.h"
@@ -35,11 +36,15 @@ enum{ S_PARA_NAME=20, PARA_NAME, S_EQUAL, S_PARA_VALUE, TAG1, TAG2, TAG3
 char* parse_to_param(char *buffer, char *end, struct to_body *to_b,
 char* parse_to_param(char *buffer, char *end, struct to_body *to_b,
 								int *returned_status)
 								int *returned_status)
 {
 {
-	struct to_param *param=0;
-	int status =PARA_START;
+	struct to_param *param;
+	int status;
 	int saved_status;
 	int saved_status;
 	char  *tmp;
 	char  *tmp;
 
 
+	param=0;
+	status=PARA_START;
+	saved_status=PARA_START;
+
 	for( tmp=buffer; tmp<end; tmp++)
 	for( tmp=buffer; tmp<end; tmp++)
 	{
 	{
 		switch(*tmp)
 		switch(*tmp)
@@ -389,11 +394,13 @@ error:
 
 
 char* parse_to(char* buffer, char *end, struct to_body *to_b)
 char* parse_to(char* buffer, char *end, struct to_body *to_b)
 {
 {
-	struct to_param *param=0;
-	int status = START_TO;
+	int status;
 	int saved_status;
 	int saved_status;
 	char  *tmp,*foo;
 	char  *tmp,*foo;
 
 
+	status=START_TO;
+	foo=0;
+
 	for( tmp=buffer; tmp<end; tmp++)
 	for( tmp=buffer; tmp<end; tmp++)
 	{
 	{
 		switch(*tmp)
 		switch(*tmp)

+ 12 - 13
parse_via.c

@@ -18,6 +18,7 @@
 
 
 
 
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 #include "dprint.h"
 #include "dprint.h"
 #include "msg_parser.h"
 #include "msg_parser.h"
 #include "ut.h"
 #include "ut.h"
@@ -208,7 +209,7 @@ char* parse_via_param(	char* p, char* end, int* pstate,
 					case F_PARAM:
 					case F_PARAM:
 					case FIN_HIDDEN:
 					case FIN_HIDDEN:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
-								" state %d\n");
+								" state %d\n", *tmp, state);
 						goto error;
 						goto error;
 					case F_CR:
 					case F_CR:
 					case F_LF:
 					case F_LF:
@@ -237,7 +238,7 @@ char* parse_via_param(	char* p, char* end, int* pstate,
 					case FIN_TTL:
 					case FIN_TTL:
 					case FIN_RECEIVED:
 					case FIN_RECEIVED:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c> in"
-								" state %d\n");
+								" state %d\n", *tmp, state);
 						goto error;
 						goto error;
 					case F_CR:
 					case F_CR:
 					case F_LF:
 					case F_LF:
@@ -585,7 +586,7 @@ goto error;
 
 
 find_value:
 find_value:
 	tmp++;
 	tmp++;
-	for(tmp;*tmp;tmp++){
+	for(;*tmp;tmp++){
 		switch(*tmp){
 		switch(*tmp){
 			case ' ':
 			case ' ':
 			case '\t':
 			case '\t':
@@ -607,7 +608,7 @@ find_value:
 						break;
 						break;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
@@ -634,7 +635,7 @@ find_value:
 						break;
 						break;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
@@ -659,7 +660,7 @@ find_value:
 						goto end_via;
 						goto end_via;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
@@ -678,7 +679,7 @@ find_value:
 						goto end_via;
 						goto end_via;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
@@ -698,7 +699,7 @@ find_value:
 						goto end_via;
 						goto end_via;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
@@ -717,7 +718,7 @@ find_value:
 						goto end_via;
 						goto end_via;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break; /* what to do? */
 				break; /* what to do? */
@@ -739,7 +740,7 @@ find_value:
 						goto end_via;
 						goto end_via;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 				break;
 				break;
@@ -759,7 +760,7 @@ find_value:
 						goto end_via;
 						goto end_via;
 					default:
 					default:
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
 						LOG(L_ERR, "ERROR: parse_via: invalid char <%c>"
-								" in state %d\n", state);
+								" in state %d\n", *tmp, state);
 						goto error;
 						goto error;
 				}
 				}
 		}
 		}
@@ -805,10 +806,8 @@ char* parse_via(char* buffer, char* end, struct via_body *vb)
 	int state;
 	int state;
 	int saved_state;
 	int saved_state;
 	int c_nest;
 	int c_nest;
-	int i;
 	int err;
 	int err;
 
 
-	char* tmp_param;
 	struct via_param* param;
 	struct via_param* param;
 
 
 parse_again:
 parse_again:

+ 0 - 3
proxy.c

@@ -139,7 +139,6 @@ void free_hostent(struct hostent *dst)
 struct proxy_l* add_proxy(char* name, unsigned short port)
 struct proxy_l* add_proxy(char* name, unsigned short port)
 {
 {
 	struct proxy_l* p;
 	struct proxy_l* p;
-	struct hostent* he;
 	
 	
 	if ((p=find_proxy(name, port))!=0) return p;
 	if ((p=find_proxy(name, port))!=0) return p;
 	if ((p=mk_proxy(name, port))==0) goto error;
 	if ((p=mk_proxy(name, port))==0) goto error;
@@ -234,8 +233,6 @@ error:
 struct proxy_l* mk_proxy_from_ip(unsigned int ip, unsigned short port)
 struct proxy_l* mk_proxy_from_ip(unsigned int ip, unsigned short port)
 {
 {
 	struct proxy_l* p;
 	struct proxy_l* p;
-	struct hostent* he;
-	int err;
 
 
 	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
 	p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
 	if (p==0){
 	if (p==0){

+ 4 - 3
receive.c

@@ -96,12 +96,13 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 			LOG(L_ERR, "ERROR: receive_msg: no via found in reply\n");
 			LOG(L_ERR, "ERROR: receive_msg: no via found in reply\n");
 			goto error;
 			goto error;
 		}
 		}
-		/*
+#if 0
 		if ((msg->via2==0) || (msg->via2->error!=VIA_PARSE_OK)){
 		if ((msg->via2==0) || (msg->via2->error!=VIA_PARSE_OK)){
-			/* no second via => error? /
+			/* no second via => error? */
 			LOG(L_ERR, "ERROR: receive_msg: no 2nd via found in reply\n");
 			LOG(L_ERR, "ERROR: receive_msg: no 2nd via found in reply\n");
 			goto error;
 			goto error;
-		}*/
+		}
+#endif
 		/* check if via1 == us */
 		/* check if via1 == us */
 
 
 #ifdef STATS
 #ifdef STATS

+ 0 - 2
route.c

@@ -273,8 +273,6 @@ static int comp_ip(unsigned a, void* param, int op, int subtype)
 	}
 	}
 	return ret;
 	return ret;
 	
 	
-error:
-	return -1;
 }
 }
 
 
 
 

+ 1 - 0
route_struct.c

@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <netinet/in.h>
+#include <string.h>
 
 
 #include "dprint.h"
 #include "dprint.h"
 
 

+ 19 - 7
sr_module.c

@@ -8,6 +8,7 @@
 #include <dlfcn.h>
 #include <dlfcn.h>
 #include <strings.h>
 #include <strings.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 
 
 
 
 struct sr_module* modules=0;
 struct sr_module* modules=0;
@@ -32,24 +33,34 @@ struct sr_module* modules=0;
 /* initializes statically built (compiled in) modules*/
 /* initializes statically built (compiled in) modules*/
 int init_builtin_modules()
 int init_builtin_modules()
 {
 {
+	int ret;
+
+	ret=0;
 	#ifdef STATIC_TM
 	#ifdef STATIC_TM
-		register_module(tm_mod_register,"built-in", 0);
+		ret=register_module(tm_mod_register,"built-in", 0);
+		if (ret<0) return ret;
 	#endif
 	#endif
 	#ifdef STATIC_MAXFWD
 	#ifdef STATIC_MAXFWD
-		register_module(maxfwd_mod_register, "built-in", 0);
+		ret=register_module(maxfwd_mod_register, "built-in", 0);
+		if (ret<0) return ret;
 	#endif
 	#endif
 
 
 #ifdef STATIC_AUTH
 #ifdef STATIC_AUTH
-		register_module(tm_mod_register, "built-in", 0);
+		ret=register_module(tm_mod_register, "built-in", 0);
+		if (ret<0) return ret;
 #endif
 #endif
 
 
 #ifdef STATIC_RR
 #ifdef STATIC_RR
-		register_module(rr_mod_register, "built-in", 0);
+		ret=register_module(rr_mod_register, "built-in", 0);
+		if (ret<0) return ret;
 #endif
 #endif
 
 
 #ifdef STATIC_USRLOC
 #ifdef STATIC_USRLOC
-		register_module(usrloc_mod_register, "built-in", 0);
+		ret=register_module(usrloc_mod_register, "built-in", 0);
+		if (ret<0) return ret;
 #endif
 #endif
+	
+	return ret;
 }
 }
 
 
 
 
@@ -60,7 +71,7 @@ int register_module(module_register register_f, char* path, void* handle)
 {
 {
 	int ret;
 	int ret;
 	struct module_exports* e;
 	struct module_exports* e;
-	struct sr_module* t, *mod;
+	struct sr_module* mod;
 	
 	
 	ret=-1;
 	ret=-1;
 	e=(*register_f)();
 	e=(*register_f)();
@@ -95,7 +106,8 @@ int init_child(int rank)
 	for(t = modules; t; t = t->next) {
 	for(t = modules; t; t = t->next) {
 		if (t->exports->init_child_f) {
 		if (t->exports->init_child_f) {
 			if ((t->exports->init_child_f(rank)) < 0) {
 			if ((t->exports->init_child_f(rank)) < 0) {
-				LOG(L_ERR, "init_child(): Initialization of child with rank %d failed\n");
+				LOG(L_ERR, "init_child(): Initialization of child %d failed\n",
+						rank);
 				return -1;
 				return -1;
 			}
 			}
 		}
 		}

+ 16 - 16
udp_server.c

@@ -25,14 +25,13 @@ int udp_sock;
 
 
 int probe_max_receive_buffer( int udp_sock )
 int probe_max_receive_buffer( int udp_sock )
 {
 {
-	int optval, optvallen;
+	int optval;
 	int ioptval;
 	int ioptval;
 	unsigned int ioptvallen;
 	unsigned int ioptvallen;
 	int foptval;
 	int foptval;
 	unsigned int foptvallen;
 	unsigned int foptvallen;
 	int voptval;
 	int voptval;
 	unsigned int voptvallen;
 	unsigned int voptvallen;
-	int i;
 	int phase=0;
 	int phase=0;
 
 
 	/* jku: try to increase buffer size as much as we can */
 	/* jku: try to increase buffer size as much as we can */
@@ -52,20 +51,21 @@ int probe_max_receive_buffer( int udp_sock )
 	for (optval=ioptval; ;  ) {
 	for (optval=ioptval; ;  ) {
 		/* increase size; double in initial phase, add linearly later */
 		/* increase size; double in initial phase, add linearly later */
 		if (phase==0) optval <<= 1; else optval+=BUFFER_INCREMENT;
 		if (phase==0) optval <<= 1; else optval+=BUFFER_INCREMENT;
-		if (optval > maxbuffer) if (phase==1) break; else { phase=1; optval >>=1; continue; }
+		if (optval > maxbuffer){
+			if (phase==1) break; 
+		} else { phase=1; optval >>=1; continue; }
 		LOG(L_DBG, "DEBUG: udp_init: trying SO_RCVBUF: %d\n", optval );
 		LOG(L_DBG, "DEBUG: udp_init: trying SO_RCVBUF: %d\n", optval );
-        	if (setsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF,
-                             (void*)&optval, sizeof(optval)) ==-1)
-        	{
+		if (setsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF,
+			(void*)&optval, sizeof(optval)) ==-1){
 			/* Solaris returns -1 if asked size too big; Linux ignores */
 			/* Solaris returns -1 if asked size too big; Linux ignores */
-			LOG(L_DBG, "DEBUG: udp_init: SOL_SOCKET failed for %d, phase %d: %s\n",
-			    optval,  phase, strerror(errno) );
+			LOG(L_DBG, "DEBUG: udp_init: SOL_SOCKET failed"
+					" for %d, phase %d: %s\n", optval, phase, strerror(errno));
 			/* if setting buffer size failed and still in the aggressive
 			/* if setting buffer size failed and still in the aggressive
 			   phase, try less agressively; otherwise give up 
 			   phase, try less agressively; otherwise give up 
 			*/
 			*/
 			if (phase==0) { phase=1; optval >>=1 ; continue; } 
 			if (phase==0) { phase=1; optval >>=1 ; continue; } 
 			else break;
 			else break;
-        	} 
+		} 
 		/* verify if change has taken effect */
 		/* verify if change has taken effect */
 		/* Linux note -- otherwise I would never know that; funny thing: Linux
 		/* Linux note -- otherwise I would never know that; funny thing: Linux
 		   doubles size for which we asked in setsockopt
 		   doubles size for which we asked in setsockopt
@@ -82,13 +82,13 @@ int probe_max_receive_buffer( int udp_sock )
 			if (voptval<optval) {
 			if (voptval<optval) {
 				LOG(L_DBG, "DEBUG: setting SO_RCVBUF has no effect\n");
 				LOG(L_DBG, "DEBUG: setting SO_RCVBUF has no effect\n");
 				/* if setting buffer size failed and still in the aggressive
 				/* if setting buffer size failed and still in the aggressive
-			   	phase, try less agressively; otherwise give up 
+				phase, try less agressively; otherwise give up 
 				*/
 				*/
-                        	if (phase==0) { phase=1; optval >>=1 ; continue; } 
-                        	else break;
+				if (phase==0) { phase=1; optval >>=1 ; continue; } 
+				else break;
 			} 
 			} 
 		}
 		}
-
+	
 	} /* for ... */
 	} /* for ... */
 	foptvallen=sizeof(foptval);
 	foptvallen=sizeof(foptval);
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &foptval,
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &foptval,
@@ -97,7 +97,7 @@ int probe_max_receive_buffer( int udp_sock )
 		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
 		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
 		return -1;
 		return -1;
 	}
 	}
- 	LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is finally %d\n", foptval );
+	LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is finally %d\n", foptval );
 
 
 	return 0;
 	return 0;
 
 
@@ -107,7 +107,7 @@ int probe_max_receive_buffer( int udp_sock )
 int udp_init(unsigned long ip, unsigned short port)
 int udp_init(unsigned long ip, unsigned short port)
 {
 {
 	struct sockaddr_in* addr;
 	struct sockaddr_in* addr;
-	int optval, optvallen;
+	int optval;
 
 
 
 
 	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr_in));
 	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr_in));
@@ -261,7 +261,7 @@ again:
 	n=sendto(udp_sock, buf, len, 0, to, tolen);
 	n=sendto(udp_sock, buf, len, 0, to, tolen);
 /*	n=sendto(udp_sock, buf, len, 0, &a2, sizeof(struct sockaddr_in) );*/
 /*	n=sendto(udp_sock, buf, len, 0, &a2, sizeof(struct sockaddr_in) );*/
 	if (n==-1){
 	if (n==-1){
-		LOG(L_ERR, "ERROR: udp_send: sendto(sock,%x,%d,0,%x,%d): %s(%d)\n",
+		LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%d,0,%p,%d): %s(%d)\n",
 				buf,len,to,tolen,
 				buf,len,to,tolen,
 				strerror(errno),errno);
 				strerror(errno),errno);
 		if (errno==EINTR) goto again;
 		if (errno==EINTR) goto again;

+ 3 - 1
ut.h

@@ -24,7 +24,9 @@
 
 
 #define trim_r( _mystr ) \
 #define trim_r( _mystr ) \
 	do{	static char _c; \
 	do{	static char _c; \
-		while( ((_mystr).len) && ((_c=(_mystr).s[(_mystr).len-1]))==0 || _c=='\r' || _c=='\n') \
+		while( ((_mystr).len) && ( ((_c=(_mystr).s[(_mystr).len-1]))==0 ||\
+									_c=='\r' || _c=='\n' ) \
+				) \
 			(_mystr).len--; \
 			(_mystr).len--; \
 	}while(0)
 	}while(0)