Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 61 additions & 72 deletions common/src/main/java/HTTPClient/HTTPConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3323,11 +3323,7 @@ Response sendRequest(Request req, int con_timeout)
Log.write(Log.CONN, "Conn: Retrying request");
continue;
}
finally
{
if (sock != null) sock.close();
}


break;
}

Expand Down Expand Up @@ -3407,39 +3403,38 @@ Response sendRequest(Request req, int con_timeout)
private Socket getSocket(int con_timeout) throws IOException
{
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 + ":" +
Log.write(Log.CONN, "Conn: Creating Socket: " + actual_host + ":" +
actual_port);

if (con_timeout == 0) // normal connection establishment
if (con_timeout == 0) // normal connection establishment
{
if (Socks_client != null)
sock = Socks_client.getSocket(actual_host, actual_port);
else
{
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<addr_list.length; idx++)
{
// try all A records
InetAddress[] addr_list = InetAddress.getAllByName(actual_host);
for (int idx=0; idx<addr_list.length; idx++)
try
{
try
if (Protocol == HTTPS)
{
if (Protocol == HTTPS)
{
//@gusbro
/* if (LocalAddr == null)
sock = new SSLSocket(addr_list[idx], actual_port,
Expand All @@ -3450,63 +3445,57 @@ private Socket getSocket(int con_timeout) throws IOException
ssl_ctxt);
((SSLSocket) sock).setAutoHandshake(false);
*/
if(LocalAddr == null)
sock = sslConnection.getSSLSocket(addr_list[idx], actual_port);
else sock = sslConnection.getSSLSocket(addr_list[idx], actual_port, LocalAddr, LocalPort);
if(LocalAddr == null)
sock = sslConnection.getSSLSocket(addr_list[idx], actual_port);
else sock = sslConnection.getSSLSocket(addr_list[idx], actual_port, LocalAddr, LocalPort);

//@iroqueta
sock.setTcpNoDelay(tcpNoDelay);
//@iroqueta
sock.setTcpNoDelay(tcpNoDelay);
//@gusbro\
}
else
{
if (LocalAddr == null)
sock = new Socket(addr_list[idx], actual_port);
else
sock = new Socket(addr_list[idx], actual_port,
LocalAddr, LocalPort);
//@iroqueta
sock.setTcpNoDelay(tcpNoDelay);
}
break; // success
}
catch (SocketException se)
else
{
if (idx == addr_list.length-1)
throw se; // we tried them all
if (LocalAddr == null)
sock = new Socket(addr_list[idx], actual_port);

Check failure

Code scanning / Fortify on Demand

Unreleased Resource: Sockets

The function getSocket() in HTTPConnection.java sometimes fails to release a socket allocated by Socket() on line 3459.The program can potentially fail to release a socket.
else
sock = new Socket(addr_list[idx], actual_port,
LocalAddr, LocalPort);
//@iroqueta
sock.setTcpNoDelay(tcpNoDelay);
}
break; // success
}
catch (SocketException se)
{
if (idx == addr_list.length-1)
throw se; // we tried them all
}
}
}
else
{
EstablishConnection con =
}
else
{
EstablishConnection con =
new EstablishConnection(actual_host, actual_port, Socks_client);
//@iroqueta
con.setTcpNoDelay(tcpNoDelay);
//@iroqueta
con.setTcpNoDelay(tcpNoDelay);

con.start();
try
{ con.join((long) con_timeout); }
catch (InterruptedException ie)
{ }
con.start();
try
{ con.join((long) con_timeout); }
catch (InterruptedException ie)
{ }

if (con.getException() != null)
throw con.getException();
if (con.getException() != null)
throw con.getException();
if ((sock = con.getSocket()) == null)
{
con.forget();
if ((sock = con.getSocket()) == null)
{
con.forget();
if ((sock = con.getSocket()) == null)
throw new InterruptedIOException("Connection establishment timed out");
}
throw new InterruptedIOException("Connection establishment timed out");
}

return sock;
}
finally
{
if (sock != null) sock.close();
}
return sock;
}


Expand Down
10 changes: 8 additions & 2 deletions common/src/main/java/HTTPClient/SocksClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,15 @@ Socket getSocket(String host, int port, InetAddress localAddr,

return sock;
}
finally
catch (IOException ioe)
{
if (sock != null) sock.close();
if (sock != null)
{
try { sock.close(); }
catch (IOException ee) {}
}

throw ioe;
}
}

Expand Down