8256818: SSLSocket that is never bound or connected leaks socket resources

Reviewed-by: xuelei
This commit is contained in:
Christoph Langer 2020-12-02 19:23:26 +00:00
parent 692b273ec5
commit 93b6ab56ae
5 changed files with 114 additions and 32 deletions

View file

@ -553,7 +553,7 @@ public final class SSLSocketImpl
// locks may be deadlocked.
@Override
public void close() throws IOException {
if (tlsIsClosed) {
if (isClosed()) {
return;
}
@ -562,19 +562,16 @@ public final class SSLSocketImpl
}
try {
// shutdown output bound, which may have been closed previously.
if (!isOutputShutdown()) {
duplexCloseOutput();
}
if (isConnected()) {
// shutdown output bound, which may have been closed previously.
if (!isOutputShutdown()) {
duplexCloseOutput();
}
// shutdown input bound, which may have been closed previously.
if (!isInputShutdown()) {
duplexCloseInput();
}
if (!isClosed()) {
// close the connection directly
closeSocket(false);
// shutdown input bound, which may have been closed previously.
if (!isInputShutdown()) {
duplexCloseInput();
}
}
} catch (IOException ioe) {
// ignore the exception
@ -582,7 +579,19 @@ public final class SSLSocketImpl
SSLLogger.warning("SSLSocket duplex close failed", ioe);
}
} finally {
tlsIsClosed = true;
if (!isClosed()) {
// close the connection directly
try {
closeSocket(false);
} catch (IOException ioe) {
// ignore the exception
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
SSLLogger.warning("SSLSocket close failed", ioe);
}
} finally {
tlsIsClosed = true;
}
}
}
}