]
Jan Kalina reassigned WFLY-8094:
--------------------------------
Assignee: Jan Kalina (was: Darran Lofthouse)
Coverity static analysis, Resource leak, LdapsecurityRealm (Elytron)
--------------------------------------------------------------------
Key: WFLY-8094
URL:
https://issues.jboss.org/browse/WFLY-8094
Project: WildFly
Issue Type: Bug
Components: Security
Reporter: Martin Choma
Assignee: Jan Kalina
Coverity static analysis found 8 occurence of Closeable object LdapIdentity not closing
properly.
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
{{LdapIdentity}} in {{close()}} method just close provided dirContext. {{LdapIdentity}}
does not create dirContext by itself. So it looks to me it is no necessary to implement
Closeable in {{LdapIdentity}}, as code where dirContext was created should be responsible
for closing it (and according to coverity it is closed properly everywhere).
{code:java|title=LdapSecurityRealm.java}
private class LdapIdentity implements Closeable {
private final String name;
private final DirContext dirContext;
private final String distinguishedName;
private final SearchResult entry;
LdapIdentity(String name, DirContext dirContext, String distinguishedName,
SearchResult entry) {
this.name = name;
this.dirContext = dirContext;
this.distinguishedName = distinguishedName;
this.entry = entry;
}
String getName() {
return this.name;
}
DirContext getDirContext() {
return this.dirContext;
}
String getDistinguishedName() {
return this.distinguishedName;
}
SearchResult getEntry() {
return this.entry;
}
@Override
public void close() throws IOException {
try {
dirContext.close();
} catch (NamingException e) {
log.debug("LdapSecurityRealm failed to close DirContext",
e);
}
}
}
{code}