From 04bda842995bc126760992199481a2bba6f38be4 Mon Sep 17 00:00:00 2001 From: Rajani Karuturi Date: Thu, 5 Mar 2015 16:54:47 +0530 Subject: [PATCH] Fixed coverity reported resource leak in LdapManagerImpl --- .../ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java index 87c0443a3c4..dfd39a3c7c1 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java @@ -74,9 +74,10 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { public LdapConfigurationResponse addConfiguration(final String hostname, final int port) throws InvalidParameterValueException { LdapConfigurationVO configuration = _ldapConfigurationDao.findByHostname(hostname); if (configuration == null) { + LdapContext context = null; try { final String providerUrl = "ldap://" + hostname + ":" + port; - _ldapContextFactory.createBindContext(providerUrl); + context = _ldapContextFactory.createBindContext(providerUrl); configuration = new LdapConfigurationVO(hostname, port); _ldapConfigurationDao.persist(configuration); s_logger.info("Added new ldap server with hostname: " + hostname); @@ -84,6 +85,8 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { } catch (NamingException | IOException e) { s_logger.debug("NamingException while doing an LDAP bind", e); throw new InvalidParameterValueException("Unable to bind to the given LDAP server"); + } finally { + closeContext(context); } } else { throw new InvalidParameterValueException("Duplicate configuration");