There appears to be a socket leak in both DatagramSocket and MulticastSocket
constructors. Both classes have constructors that create a socket and then
attempt to bind. The bind can fail with a variety of exceptions none of which
are caught by the constructor. Thus, the actual system socket that was
allocated by impl.create() is never closed.
My fix was to wrap a try-finally around the bind call and call close() if
isBound is false.
public DatagramSocket(SocketAddress bindaddr) throws SocketException {
// create a datagram socket.
createImpl();
if (bindaddr != null) {
try {
bind(bindaddr);
} finally {
if( !isBound() )
close();
}
}
}
Tom Salter
Unisys Corporation