diff --git a/client/http_resolve_host.c b/client/http_resolve_host.c index b3f2ddc8..b4b89979 100644 --- a/client/http_resolve_host.c +++ b/client/http_resolve_host.c @@ -57,7 +57,7 @@ try_url(struct url *url, fko_cli_options_t *options) int sock=-1, sock_success=0, res, error, http_buf_len, i; int bytes_read = 0, position = 0; int o1, o2, o3, o4; - struct addrinfo *result, *rp, hints; + struct addrinfo *result=NULL, *rp, hints; char http_buf[HTTP_MAX_REQUEST_LEN] = {0}; char http_response[HTTP_MAX_RESPONSE_LEN] = {0}; char *ndx; @@ -112,21 +112,25 @@ try_url(struct url *url, fko_cli_options_t *options) sock_success = 1; break; /* made it */ } + else /* close the open socket if there was a connect error */ + { +#ifdef WIN32 + closesocket(sock); +#else + close(sock); +#endif + } + } + if(result != NULL) + freeaddrinfo(result); if (! sock_success) { log_msg(LOG_VERBOSITY_ERROR, "resolve_ip_http: Could not create socket: ", strerror(errno)); -#ifdef WIN32 - closesocket(sock); -#else - close(sock); -#endif return(-1); } - freeaddrinfo(result); - log_msg(LOG_VERBOSITY_DEBUG, "\nHTTP request: %s", http_buf); res = send(sock, http_buf, http_buf_len, 0); diff --git a/client/spa_comm.c b/client/spa_comm.c index 51b57880..20a9b196 100644 --- a/client/spa_comm.c +++ b/client/spa_comm.c @@ -87,7 +87,7 @@ send_spa_packet_tcp_or_udp(const char *spa_data, const int sd_len, const fko_cli_options_t *options) { int sock=-1, sock_success=0, res=0, error; - struct addrinfo *result, *rp, hints; + struct addrinfo *result=NULL, *rp, hints; char port_str[MAX_PORT_STR_LEN+1] = {0}; if (options->test) @@ -138,22 +138,25 @@ send_spa_packet_tcp_or_udp(const char *spa_data, const int sd_len, sock_success = 1; break; /* made it */ } + else /* close the open socket if there was a connect error */ + { +#ifdef WIN32 + closesocket(sock); +#else + close(sock); +#endif + } } + if(result != NULL) + freeaddrinfo(result); if (! sock_success) { log_msg(LOG_VERBOSITY_ERROR, "send_spa_packet_tcp_or_udp: Could not create socket: ", strerror(errno)); -#ifdef WIN32 - closesocket(sock); -#else - close(sock); -#endif return -1; } - freeaddrinfo(result); - res = send(sock, spa_data, sd_len, 0); if(res < 0)