< prev index next >

src/share/classes/sun/security/ssl/SSLSocketImpl.java

Print this page
rev 14317 : 8256818: SSLSocket that is never bound or connected leaks socket resources
Reviewed-by: xuelei

@@ -455,42 +455,51 @@
 
     // Please don't synchronized this method.  Otherwise, the read and close
     // locks may be deadlocked.
     @Override
     public void close() throws IOException {
-        if (tlsIsClosed) {
+        if (isClosed()) {
             return;
         }
 
         if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
             SSLLogger.fine("duplex close of SSLSocket");
         }
 
         try {
+            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();
             }
-
+            }
+        } catch (IOException ioe) {
+            // ignore the exception
+            if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
+                SSLLogger.warning("SSLSocket duplex close failed", ioe);
+            }
+        } finally {
             if (!isClosed()) {
                 // close the connection directly
+                try {
                 closeSocket(false);
-            }
         } catch (IOException ioe) {
             // ignore the exception
             if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
-                SSLLogger.warning("SSLSocket duplex close failed", ioe);
+                        SSLLogger.warning("SSLSocket close failed", ioe);
             }
         } finally {
             tlsIsClosed = true;
         }
     }
+        }
+    }
 
     /**
      * Duplex close, start from closing outbound.
      *
      * For TLS 1.2 [RFC 5246], unless some other fatal alert has been
< prev index next >