diff --git a/common/src/main/java/HTTPClient/HTTPConnection.java b/common/src/main/java/HTTPClient/HTTPConnection.java index 0e22ee77b..91eadf629 100644 --- a/common/src/main/java/HTTPClient/HTTPConnection.java +++ b/common/src/main/java/HTTPClient/HTTPConnection.java @@ -3192,11 +3192,11 @@ Response sendRequest(Request req, int con_timeout) while (try_count-- > 0) { + Socket sock = null; try { // get a client socket - Socket sock; if (input_demux == null || (sock = input_demux.getSocket()) == null) { @@ -3323,6 +3323,10 @@ Response sendRequest(Request req, int con_timeout) Log.write(Log.CONN, "Conn: Retrying request"); continue; } + finally + { + if (sock != null) sock.close(); + } break; } @@ -3402,39 +3406,40 @@ Response sendRequest(Request req, int con_timeout) */ private Socket getSocket(int con_timeout) throws IOException { - Socket sock = null; + Socket sock = null; + try { - String actual_host; - int actual_port; + String actual_host; + int actual_port; - if (Proxy_Host != null) - { - actual_host = Proxy_Host; - actual_port = Proxy_Port; - } - else - { - actual_host = Host; - actual_port = Port; - } + if (Proxy_Host != null) + { + actual_host = Proxy_Host; + actual_port = Proxy_Port; + } + else + { + actual_host = Host; + actual_port = Port; + } - Log.write(Log.CONN, "Conn: Creating Socket: " + actual_host + ":" + - actual_port); + Log.write(Log.CONN, "Conn: Creating Socket: " + actual_host + ":" + + actual_port); - if (con_timeout == 0) // normal connection establishment - { - if (Socks_client != null) - sock = Socks_client.getSocket(actual_host, actual_port); - else - { - // try all A records - InetAddress[] addr_list = InetAddress.getAllByName(actual_host); - for (int idx=0; idx