Uploaded image for project: 'WildFly Elytron'
  1. WildFly Elytron
  2. ELY-965

Coverity static analysis, Resource leak, LdapsecurityRealm (Elytron)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.1.0.Beta26
    • None
    • Realms
    • None

      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).

      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);
                      }
                  }
              }
      

              jkalina@redhat.com Jan Kalina (Inactive)
              mchoma@redhat.com Martin Choma
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: