Skip to content

Commit

Permalink
Close the socket when an exception is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhenyu committed Nov 14, 2023
1 parent 30780c8 commit 424b22d
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public UnixDomainSocketFactory(File path) {

@Override public Socket createSocket(String host, int port) throws IOException {
Socket result = createSocket();
result.connect(new InetSocketAddress(host, port));

try {
result.connect(new InetSocketAddress(host, port));
} catch (IOException e) {
result.close();
}
return result;
}

Expand All @@ -49,7 +54,12 @@ public UnixDomainSocketFactory(File path) {

@Override public Socket createSocket(InetAddress host, int port) throws IOException {
Socket result = createSocket();
result.connect(new InetSocketAddress(host, port));

try {
result.connect(new InetSocketAddress(host, port));
} catch (IOException e) {
result.close();
}
return result;
}

Expand Down

0 comments on commit 424b22d

Please sign in to comment.