6717680: LdapCtx does not close the connection if initialization fails
authorweijun
Tue, 30 Dec 2008 10:42:45 +0800
changeset 2605 e8d0473c25e8
parent 2604 0420efe42fbb
child 2606 09ad5edb5330
6717680: LdapCtx does not close the connection if initialization fails Reviewed-by: vinnie, xuelei
jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java	Wed Dec 24 15:48:59 2008 -0800
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java	Tue Dec 30 10:42:45 2008 +0800
@@ -302,7 +302,16 @@
 
         schemaTrees = new Hashtable(11, 0.75f);
         initEnv();
-        connect(false);
+        try {
+            connect(false);
+        } catch (NamingException e) {
+            try {
+                close();
+            } catch (Exception e2) {
+                // Nothing
+            }
+            throw e;
+        }
     }
 
     LdapCtx(LdapCtx existing, String newDN) throws NamingException {