[jboss-jira] [JBoss JIRA] (WFLY-8094) Coverity static analysis, Resource leak, LdapsecurityRealm (Elytron)

Martin Choma (JIRA) issues at jboss.org
Mon Feb 13 07:39:02 EST 2017


Martin Choma created WFLY-8094:
----------------------------------

             Summary: 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: Darran Lofthouse


Coverity static analysis found 8 occurence of Closeable object LdapIdentity not closing properly. 

https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359307&mergedDefectId=1400389
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359304&mergedDefectId=1400388
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359309&mergedDefectId=1400387
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359306&mergedDefectId=1400386
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359311&mergedDefectId=1400385
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359312&mergedDefectId=1400384
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359313&mergedDefectId=1400383
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=9564393&defectInstanceId=2359303&mergedDefectId=1400382

{{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}




--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the jboss-jira mailing list