Changeset f710673
- Timestamp:
- 2015-10-26T03:42:12Z (9 years ago)
- Branches:
- master
- Children:
- 4e365ce
- Parents:
- 5756890
- git-author:
- dequis <dx@…> (24-10-15 21:41:38)
- git-committer:
- dequis <dx@…> (26-10-15 03:42:12)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/proxy.c
r5756890 rf710673 65 65 static int proxy_connect_none(const char *host, unsigned short port_, struct PHB *phb); 66 66 67 static gboolean phb_close(struct PHB *phb) 68 { 69 close(phb->fd); 70 phb->func(phb->data, -1, B_EV_IO_READ); 67 static gboolean phb_free(struct PHB *phb, gboolean success) 68 { 69 if (!success) { 70 if (phb->fd > 0) { 71 closesocket(phb->fd); 72 } 73 if (phb->func) { 74 phb->func(phb->data, -1, B_EV_IO_READ); 75 } 76 } 77 if (phb->gai) { 78 freeaddrinfo(phb->gai); 79 } 71 80 g_free(phb->host); 72 81 g_free(phb); … … 103 112 104 113 freeaddrinfo(phb->gai); 114 phb->gai = NULL; 115 105 116 b_event_remove(phb->inpa); 106 117 phb->inpa = 0; 118 107 119 if (phb->proxy_func) { 108 120 phb->proxy_func(phb->proxy_data, source, B_EV_IO_READ); 109 121 } else { 110 122 phb->func(phb->data, source, B_EV_IO_READ); 111 g_free(phb);123 phb_free(phb, TRUE); 112 124 } 113 125 … … 173 185 174 186 if (fd < 0 && host) { 175 g_free(phb);187 phb_free(phb, TRUE); 176 188 } 177 189 … … 206 218 (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) { 207 219 phb->func(phb->data, source, B_EV_IO_READ); 208 g_free(phb->host); 209 g_free(phb); 210 return FALSE; 211 } 212 213 return phb_close(phb); 220 return phb_free(phb, TRUE); 221 } 222 223 return phb_free(phb, FALSE); 214 224 } 215 225 … … 226 236 len = sizeof(error); 227 237 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 228 return phb_ close(phb);238 return phb_free(phb, FALSE); 229 239 } 230 240 sock_make_blocking(source); … … 233 243 phb->host, phb->port); 234 244 if (send(source, cmd, strlen(cmd), 0) < 0) { 235 return phb_ close(phb);245 return phb_free(phb, FALSE); 236 246 } 237 247 … … 244 254 g_free(t2); 245 255 if (send(source, cmd, strlen(cmd), 0) < 0) { 246 return phb_ close(phb);256 return phb_free(phb, FALSE); 247 257 } 248 258 } … … 250 260 g_snprintf(cmd, sizeof(cmd), "\r\n"); 251 261 if (send(source, cmd, strlen(cmd), 0) < 0) { 252 return phb_ close(phb);262 return phb_free(phb, FALSE); 253 263 } 254 264 … … 281 291 if (read(source, packet, 9) >= 4 && packet[1] == 90) { 282 292 phb->func(phb->data, source, B_EV_IO_READ); 283 g_free(phb->host); 284 g_free(phb); 285 return FALSE; 286 } 287 288 return phb_close(phb); 293 return phb_free(phb, TRUE); 294 } 295 296 return phb_free(phb, FALSE); 289 297 } 290 298 … … 303 311 len = sizeof(error); 304 312 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 305 return phb_ close(phb);313 return phb_free(phb, FALSE); 306 314 } 307 315 sock_make_blocking(source); 308 316 309 317 if (!is_socks4a && !(hp = gethostbyname(phb->host))) { 310 return phb_ close(phb);318 return phb_free(phb, FALSE); 311 319 } 312 320 … … 328 336 packet[8] = 0; 329 337 if (write(source, packet, 9) != 9) { 330 return phb_ close(phb);338 return phb_free(phb, FALSE); 331 339 } 332 340 … … 335 343 336 344 if (write(source, phb->host, host_len) != host_len) { 337 return phb_ close(phb);345 return phb_free(phb, FALSE); 338 346 } 339 347 } … … 365 373 366 374 if (read(source, buf, 10) < 10) { 367 return phb_ close(phb);375 return phb_free(phb, FALSE); 368 376 } 369 377 if ((buf[0] != 0x05) || (buf[1] != 0x00)) { 370 return phb_ close(phb);378 return phb_free(phb, FALSE); 371 379 } 372 380 373 381 phb->func(phb->data, source, B_EV_IO_READ); 374 g_free(phb->host); 375 g_free(phb); 376 377 return FALSE; 382 return phb_free(phb, TRUE); 378 383 } 379 384 … … 394 399 395 400 if (write(source, buf, (5 + strlen(phb->host) + 2)) < (5 + strlen(phb->host) + 2)) { 396 phb_ close(phb);401 phb_free(phb, FALSE); 397 402 return; 398 403 } … … 409 414 410 415 if (read(source, buf, 2) < 2) { 411 return phb_ close(phb);416 return phb_free(phb, FALSE); 412 417 } 413 418 414 419 if ((buf[0] != 0x01) || (buf[1] != 0x00)) { 415 return phb_ close(phb);420 return phb_free(phb, FALSE); 416 421 } 417 422 … … 429 434 430 435 if (read(source, buf, 2) < 2) { 431 return phb_ close(phb);436 return phb_free(phb, FALSE); 432 437 } 433 438 434 439 if ((buf[0] != 0x05) || (buf[1] == 0xff)) { 435 return phb_ close(phb);440 return phb_free(phb, FALSE); 436 441 } 437 442 … … 444 449 memcpy(buf + 2 + i + 1, proxypass, j); 445 450 if (write(source, buf, 3 + i + j) < 3 + i + j) { 446 return phb_ close(phb);451 return phb_free(phb, FALSE); 447 452 } 448 453 … … 468 473 len = sizeof(error); 469 474 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 470 return phb_ close(phb);475 return phb_free(phb, FALSE); 471 476 } 472 477 sock_make_blocking(source); … … 486 491 487 492 if (write(source, buf, i) < i) { 488 return phb_ close(phb);493 return phb_free(phb, FALSE); 489 494 } 490 495
Note: See TracChangeset
for help on using the changeset viewer.