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
|
||||
*/
|
||||
public DatagramSocket() throws SocketException {
|
||||
// create a datagram socket.
|
||||
createImpl();
|
||||
bind(new InetSocketAddress(0));
|
||||
this(new InetSocketAddress(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +219,12 @@ class DatagramSocket implements java.io.Closeable {
|
||||
// create a datagram socket.
|
||||
createImpl();
|
||||
if (bindaddr != null) {
|
||||
bind(bindaddr);
|
||||
try {
|
||||
bind(bindaddr);
|
||||
} finally {
|
||||
if (!isBound())
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,12 @@ class MulticastSocket extends DatagramSocket {
|
||||
setReuseAddress(true);
|
||||
|
||||
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) {
|
||||
close();
|
||||
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