... | ... |
@@ -69,9 +69,16 @@ int forward_request(char * orig, char* buf, |
69 | 69 |
char received_buf[MAX_RECEIVED_SIZE]; |
70 | 70 |
char* new_buf; |
71 | 71 |
int offset, s_offset, size; |
72 |
- struct sockaddr_in to; |
|
72 |
+ struct sockaddr_in* to; |
|
73 | 73 |
|
74 | 74 |
received_len=0; |
75 |
+ new_buf=0; |
|
76 |
+ to=0; |
|
77 |
+ to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
|
78 |
+ if (to==0){ |
|
79 |
+ DPrint("ERROR: forward_reply: out of memory\n"); |
|
80 |
+ goto error; |
|
81 |
+ } |
|
75 | 82 |
|
76 | 83 |
via_len=snprintf(line_buf, MAX_VIA_LINE_SIZE, "Via: SIP/2.0/UDP %s:%d\r\n", |
77 | 84 |
names[0], port_no); |
... | ... |
@@ -86,7 +93,7 @@ int forward_request(char * orig, char* buf, |
86 | 93 |
new_buf=(char*)malloc(new_len+1); |
87 | 94 |
if (new_buf==0){ |
88 | 95 |
DPrint("ERROR: forward_request: out of memory\n"); |
89 |
- goto error1; |
|
96 |
+ goto error; |
|
90 | 97 |
} |
91 | 98 |
/* copy msg till first via */ |
92 | 99 |
offset=s_offset=0; |
... | ... |
@@ -123,8 +130,8 @@ int forward_request(char * orig, char* buf, |
123 | 130 |
printf("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n", |
124 | 131 |
len, new_len, via_len, received_len); |
125 | 132 |
|
126 |
- to.sin_family = AF_INET; |
|
127 |
- to.sin_port = (re->port)?htons(re->port):htons(SIP_PORT); |
|
133 |
+ to->sin_family = AF_INET; |
|
134 |
+ to->sin_port = (re->port)?htons(re->port):htons(SIP_PORT); |
|
128 | 135 |
/* if error try next ip address if possible */ |
129 | 136 |
if (re->ok==0){ |
130 | 137 |
if (re->host.h_addr_list[re->current_addr_idx+1]) |
... | ... |
@@ -132,21 +139,22 @@ int forward_request(char * orig, char* buf, |
132 | 139 |
re->ok=1; |
133 | 140 |
} |
134 | 141 |
/* ? not 64bit clean?*/ |
135 |
- to.sin_addr.s_addr=*((long*)re->host.h_addr_list[re->current_addr_idx]); |
|
142 |
+ to->sin_addr.s_addr=*((long*)re->host.h_addr_list[re->current_addr_idx]); |
|
136 | 143 |
|
137 | 144 |
re->tx++; |
138 | 145 |
re->tx_bytes+=new_len; |
139 |
- if (udp_send(new_buf, new_len, &to, sizeof(to))==-1){ |
|
146 |
+ if (udp_send(new_buf, new_len, to, sizeof(struct sockaddr))==-1){ |
|
140 | 147 |
re->errors++; |
141 | 148 |
re->ok=0; |
142 | 149 |
goto error; |
143 | 150 |
} |
144 | 151 |
|
145 | 152 |
free(new_buf); |
153 |
+ free(to); |
|
146 | 154 |
return 0; |
147 | 155 |
error: |
148 |
- free(new_buf); |
|
149 |
-error1: |
|
156 |
+ if (new_buf) free(new_buf); |
|
157 |
+ if (to) free(to); |
|
150 | 158 |
return -1; |
151 | 159 |
|
152 | 160 |
} |
... | ... |
@@ -164,9 +172,15 @@ int forward_reply(char * orig, char* buf, |
164 | 172 |
char* new_buf; |
165 | 173 |
int offset, s_offset, size; |
166 | 174 |
struct hostent* he; |
167 |
- struct sockaddr_in to; |
|
175 |
+ struct sockaddr_in* to; |
|
168 | 176 |
|
169 | 177 |
new_buf=0; |
178 |
+ to=0; |
|
179 |
+ to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
|
180 |
+ if (to==0){ |
|
181 |
+ DPrint("ERROR: forward_reply: out of memory\n"); |
|
182 |
+ goto error; |
|
183 |
+ } |
|
170 | 184 |
|
171 | 185 |
/*check if first via host = us */ |
172 | 186 |
if (check_via){ |
... | ... |
@@ -209,17 +223,19 @@ int forward_reply(char * orig, char* buf, |
209 | 223 |
DPrint("ERROR:forward_reply:gethostbyname failure\n"); |
210 | 224 |
goto error; |
211 | 225 |
} |
212 |
- to.sin_family = AF_INET; |
|
213 |
- to.sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT); |
|
214 |
- to.sin_addr.s_addr=*((long*)he->h_addr_list[0]); |
|
226 |
+ to->sin_family = AF_INET; |
|
227 |
+ to->sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT); |
|
228 |
+ to->sin_addr.s_addr=*((long*)he->h_addr_list[0]); |
|
215 | 229 |
|
216 | 230 |
if (udp_send(new_buf,new_len, &to, sizeof(to))==-1) |
217 | 231 |
goto error; |
218 | 232 |
|
219 | 233 |
free(new_buf); |
234 |
+ free(to); |
|
220 | 235 |
return 0; |
221 | 236 |
|
222 | 237 |
error: |
223 | 238 |
if (new_buf) free(new_buf); |
239 |
+ if (to) free(to); |
|
224 | 240 |
return -1; |
225 | 241 |
} |
... | ... |
@@ -19,12 +19,17 @@ int udp_sock; |
19 | 19 |
|
20 | 20 |
int udp_init(unsigned long ip, unsigned short port) |
21 | 21 |
{ |
22 |
- struct sockaddr_in addr; |
|
22 |
+ struct sockaddr_in* addr; |
|
23 | 23 |
int optval; |
24 | 24 |
|
25 |
- addr.sin_family=AF_INET; |
|
26 |
- addr.sin_port=htons(port); |
|
27 |
- addr.sin_addr.s_addr=ip; |
|
25 |
+ addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
|
26 |
+ if (addr==0){ |
|
27 |
+ DPrint("ERROR: udp_init: out of memory\n"); |
|
28 |
+ goto error; |
|
29 |
+ } |
|
30 |
+ addr->sin_family=AF_INET; |
|
31 |
+ addr->sin_port=htons(port); |
|
32 |
+ addr->sin_addr.s_addr=ip; |
|
28 | 33 |
|
29 | 34 |
udp_sock = socket(PF_INET, SOCK_DGRAM, 0); |
30 | 35 |
if (udp_sock==-1){ |
... | ... |
@@ -40,15 +45,16 @@ int udp_init(unsigned long ip, unsigned short port) |
40 | 45 |
goto error; |
41 | 46 |
} |
42 | 47 |
|
43 |
- if (bind(udp_sock, (struct sockaddr*) &addr, sizeof(addr))==-1){ |
|
48 |
+ if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){ |
|
44 | 49 |
DPrint("ERROR: udp_init: bind: %s\n", strerror()); |
45 | 50 |
goto error; |
46 | 51 |
} |
47 | 52 |
|
48 |
- |
|
53 |
+ free(addr); |
|
49 | 54 |
return 0; |
50 | 55 |
|
51 | 56 |
error: |
57 |
+ if (addr) free(addr); |
|
52 | 58 |
return -1; |
53 | 59 |
} |
54 | 60 |
|