Skip to content

fix NamingEnumeration not closed #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.util.Assert;

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
Expand Down Expand Up @@ -166,8 +167,9 @@ public boolean validateDirContext(DirContextType contextType, DirContext dirCont
Assert.notNull(contextType, "contextType may not be null");
Assert.notNull(dirContext, "dirContext may not be null");

NamingEnumeration<SearchResult> searchResults = null;
try {
final NamingEnumeration<SearchResult> searchResults = dirContext.search(this.base, this.filter, this.searchControls);
searchResults = dirContext.search(this.base, this.filter, this.searchControls);

if (searchResults.hasMore()) {
this.logger.debug("DirContext '{}' passed validation.", dirContext);
Expand All @@ -179,6 +181,15 @@ public boolean validateDirContext(DirContextType contextType, DirContext dirCont
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, e);
return false;
}
finally {
if (searchResults != null) {
try {
searchResults.close();
}
catch (NamingException e) {
}
}
}

this.logger.debug("DirContext '{}' failed validation.", dirContext);
return false;
Expand Down