提交 393c00fe 编写于 作者: M michaelm

7085981: XXSocket types depend on impl finalizer to close if constructor throws exception

Reviewed-by: alanb, chegar
上级 6a8f08cb
......@@ -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();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册