Datagram socket leak
Chris Hegarty
chris.hegarty at oracle.com
Mon Aug 29 10:10:18 PDT 2011
I haven't looked at the code in question in detail, but from the code
snippet, won't the finally close the socket ( since it is not isBound )?
-Chris.
On 08/29/11 03:27 PM, Salter, Thomas A wrote:
> 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
>
More information about the net-dev
mailing list