Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-641

Resource Leakage when loading keystore in AuthSSLProtocolSocketFactory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.1
    • 3.1 RC1
    • Contrib
    • None
    • All

    Description

      Opened stream not closed after keystore is loaded, resulting in resource leakage:

      private static KeyStore createKeyStore(final URL url, final String password)
      throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
      {
      if (url == null)

      { throw new IllegalArgumentException("Keystore url may not be null"); }
      LOG.debug("Initializing key store");
      KeyStore keystore = KeyStore.getInstance("jks");
      keystore.load(url.openStream(), password != null ? password.toCharArray(): null);
      return keystore;
      }

      Should be changed to something like:

      private static KeyStore createKeyStore(final URL url, final String password)
      throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
      {
      if (url == null) { throw new IllegalArgumentException("Keystore url may not be null"); }

      LOG.debug("Initializing key store");
      KeyStore keystore = KeyStore.getInstance("jks");
      InputStream is = ulr.openStream();
      try

      { keystore.load(is, password != null ? password.toCharArray(): null); }

      finally

      { is.close(); }

      return keystore;
      }

      Attachments

        1. patch.txt
          5 kB
          Ortwin Glueck

        Activity

          People

            oglueck Ortwin Glueck
            hchar Hanson Char
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: