svn commit: r966785 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r966785 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java

doogie-3
Author: doogie
Date: Thu Jul 22 18:30:51 2010
New Revision: 966785

URL: http://svn.apache.org/viewvc?rev=966785&view=rev
Log:
Fix file leak problem in KeyStore, the stream must be closed by the
caller(which also generally means doing it in a finally clause).

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java?rev=966785&r1=966784&r2=966785&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/KeyStoreUtil.java Thu Jul 22 18:30:51 2010
@@ -66,7 +66,11 @@ public class KeyStoreUtil {
         ComponentConfig.KeystoreInfo ks = ComponentConfig.getKeystoreInfo(componentName, keyStoreName);
         File file = FileUtil.getFile(ks.createResourceHandler().getFullLocation());
         FileOutputStream out = new FileOutputStream(file);
-        store.store(out, ks.getPassword().toCharArray());
+        try {
+            store.store(out, ks.getPassword().toCharArray());
+        } finally {
+            out.close();
+        }
     }
 
     public static KeyStore getComponentKeyStore(String componentName, String keyStoreName) throws IOException, GeneralSecurityException, GenericConfigException {
@@ -83,7 +87,12 @@ public class KeyStoreUtil {
             throw new IOException("Invalid keystore type; null");
         }
         KeyStore ks = KeyStore.getInstance(type);
-        ks.load(url.openStream(), password.toCharArray());
+        InputStream in = url.openStream();
+        try {
+            ks.load(in, password.toCharArray());
+        } finally {
+            in.close();
+        }
         return ks;
     }
 
@@ -107,7 +116,12 @@ public class KeyStoreUtil {
         }
 
         if (keyFile.exists() && keyFile.canRead()) {
-            ks.load(new FileInputStream(keyFile), password.toCharArray());
+            InputStream in = new FileInputStream(keyFile);
+            try {
+                ks.load(in, password.toCharArray());
+            } finally {
+                in.close();
+            }
         } else {
             ks.load(null, "changeit".toCharArray());
         }