7085981: XXSocket types depend on impl finalizer to close if constructor throws exception
Reviewed-by: alanb, chegar
This commit is contained in:
parent
6b8980e983
commit
518e846e10
@ -174,9 +174,7 @@ class DatagramSocket implements java.io.Closeable {
|
|||||||
* @see SecurityManager#checkListen
|
* @see SecurityManager#checkListen
|
||||||
*/
|
*/
|
||||||
public DatagramSocket() throws SocketException {
|
public DatagramSocket() throws SocketException {
|
||||||
// create a datagram socket.
|
this(new InetSocketAddress(0));
|
||||||
createImpl();
|
|
||||||
bind(new InetSocketAddress(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,7 +219,12 @@ class DatagramSocket implements java.io.Closeable {
|
|||||||
// create a datagram socket.
|
// create a datagram socket.
|
||||||
createImpl();
|
createImpl();
|
||||||
if (bindaddr != null) {
|
if (bindaddr != null) {
|
||||||
bind(bindaddr);
|
try {
|
||||||
|
bind(bindaddr);
|
||||||
|
} finally {
|
||||||
|
if (!isBound())
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,12 @@ class MulticastSocket extends DatagramSocket {
|
|||||||
setReuseAddress(true);
|
setReuseAddress(true);
|
||||||
|
|
||||||
if (bindaddr != null) {
|
if (bindaddr != null) {
|
||||||
bind(bindaddr);
|
try {
|
||||||
|
bind(bindaddr);
|
||||||
|
} finally {
|
||||||
|
if (!isBound())
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,6 +425,10 @@ class Socket implements java.io.Closeable {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
close();
|
close();
|
||||||
throw e;
|
throw e;
|
||||||
|
} finally {
|
||||||
|
// if bind() or connect threw a runtime exception
|
||||||
|
if ((localAddr != null && !bound) || (address != null && !connected))
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user