Skip to content

Commit

Permalink
Fix #5794 Close socket on bind failure
Browse files Browse the repository at this point in the history
Fix #5794 Close socket on bind failure
  • Loading branch information
gregw committed Dec 12, 2020
1 parent 9349ed2 commit 7125d8d
Showing 1 changed file with 1 addition and 9 deletions.
Expand Up @@ -176,15 +176,7 @@ public int freePort() throws IOException
try (ServerSocket server = new ServerSocket())
{
server.setReuseAddress(true);
try
{
server.bind(new InetSocketAddress("localhost", 0));
}
catch (Throwable t)
{
IO.close(server);
throw t;
}
server.bind(new InetSocketAddress("localhost", 0));
return server.getLocalPort();
}
}
Expand Down

0 comments on commit 7125d8d

Please sign in to comment.