6588160: jaas krb5 client leaks OS-level UDP sockets (all platforms)
authorweijun
Wed, 01 Oct 2008 10:01:45 +0800
changeset 2597 31ee39bed77f
parent 2596 a1964c157e68
child 2598 6f980e1d6e31
6588160: jaas krb5 client leaks OS-level UDP sockets (all platforms) Reviewed-by: jccollet, chegar
jdk/src/share/classes/sun/security/krb5/KrbKdcReq.java
jdk/src/share/classes/sun/security/krb5/internal/UDPClient.java
--- a/jdk/src/share/classes/sun/security/krb5/KrbKdcReq.java	Fri Aug 22 18:48:00 2008 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/KrbKdcReq.java	Wed Oct 01 10:01:45 2008 +0800
@@ -274,27 +274,31 @@
                                + ",Attempt =" + i
                                + ", #bytes=" + obuf.length);
                     }
-                    /*
-                     * Send the data to the kdc.
-                     */
+                    try {
+                        /*
+                         * Send the data to the kdc.
+                         */
 
                     kdcClient.send(obuf);
 
-                    /*
-                     * And get a response.
-                     */
-                    try {
-                        ibuf = kdcClient.receive();
-                        break;
-                    } catch (SocketTimeoutException se) {
-                        if (DEBUG) {
-                            System.out.println ("SocketTimeOutException with " +
-                                                "attempt: " + i);
+                        /*
+                         * And get a response.
+                         */
+                        try {
+                            ibuf = kdcClient.receive();
+                            break;
+                        } catch (SocketTimeoutException se) {
+                            if (DEBUG) {
+                                System.out.println ("SocketTimeOutException with " +
+                                                    "attempt: " + i);
+                            }
+                            if (i == DEFAULT_KDC_RETRY_LIMIT) {
+                                ibuf = null;
+                                throw se;
+                            }
                         }
-                        if (i == DEFAULT_KDC_RETRY_LIMIT) {
-                            ibuf = null;
-                            throw se;
-                        }
+                    } finally {
+                        kdcClient.close();
                     }
                 }
             }
--- a/jdk/src/share/classes/sun/security/krb5/internal/UDPClient.java	Fri Aug 22 18:48:00 2008 -0700
+++ b/jdk/src/share/classes/sun/security/krb5/internal/UDPClient.java	Wed Oct 01 10:01:45 2008 +0800
@@ -93,4 +93,7 @@
         return data;
     }
 
+    public void close() {
+        dgSocket.close();
+    }
 }