You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/10/06 04:57:08 UTC

[11/24] git commit: SLIDER-374 Potential resource leak in accumulo/CertUtil.java due to unclosed streams (Thomas Liu)

SLIDER-374 Potential resource leak in accumulo/CertUtil.java due to unclosed streams (Thomas Liu)


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/fef98cd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/fef98cd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/fef98cd6

Branch: refs/heads/feature/SLIDER-149_Support_a_YARN_service_registry
Commit: fef98cd64a73b7e4e215e810f18c99c4b942afee
Parents: 2051dd6
Author: tedyu <yu...@gmail.com>
Authored: Fri Oct 3 11:22:30 2014 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Fri Oct 3 11:22:30 2014 -0700

----------------------------------------------------------------------
 .../slider/funtest/accumulo/CertUtil.java       | 50 ++++++++++++++++++--
 1 file changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/fef98cd6/app-packages/accumulo/src/test/java/org/apache/slider/funtest/accumulo/CertUtil.java
----------------------------------------------------------------------
diff --git a/app-packages/accumulo/src/test/java/org/apache/slider/funtest/accumulo/CertUtil.java b/app-packages/accumulo/src/test/java/org/apache/slider/funtest/accumulo/CertUtil.java
index 4aba31f..8bac58f 100644
--- a/app-packages/accumulo/src/test/java/org/apache/slider/funtest/accumulo/CertUtil.java
+++ b/app-packages/accumulo/src/test/java/org/apache/slider/funtest/accumulo/CertUtil.java
@@ -97,13 +97,29 @@ public class CertUtil {
       IOException, CertificateException, NoSuchAlgorithmException {
     KeyStore signerKeystore = KeyStore.getInstance(keystoreType);
     char[] signerPasswordArray = rootKeystorePassword;
-    signerKeystore.load(new FileInputStream(rootKeystorePath), signerPasswordArray);
+    FileInputStream rootKeystoreInputStream = null;
+    try{
+        rootKeystoreInputStream = new FileInputStream(rootKeystorePath);
+        signerKeystore.load(rootKeystoreInputStream, signerPasswordArray);
+    } finally {
+        if(rootKeystoreInputStream != null) {
+            rootKeystoreInputStream.close();
+        }
+    }
     Certificate rootCert = findCert(signerKeystore);
 
     KeyStore keystore = KeyStore.getInstance(keystoreType);
     keystore.load(null, null);
     keystore.setCertificateEntry(keyName + "Cert", rootCert);
-    keystore.store(new FileOutputStream(targetKeystoreFile), truststorePassword);
+    FileOutputStream targetKeystoreOutputStream = null;
+    try{
+        targetKeystoreOutputStream = new FileOutputStream(targetKeystoreFile);
+        keystore.store(targetKeystoreOutputStream, truststorePassword);
+    } finally {
+        if(targetKeystoreOutputStream != null) {
+            targetKeystoreOutputStream.close();
+        }
+    }
   }
 
   public static void createSignedCert(String targetKeystoreFile,
@@ -112,7 +128,15 @@ public class CertUtil {
       throws Exception {
     KeyStore signerKeystore = KeyStore.getInstance(keystoreType);
     char[] signerPasswordArray = signerKeystorePassword;
-    signerKeystore.load(new FileInputStream(signerKeystorePath), signerPasswordArray);
+    FileInputStream signerKeystoreInputStream = null;
+    try{
+        signerKeystoreInputStream = new FileInputStream(signerKeystorePath);
+        signerKeystore.load(signerKeystoreInputStream, signerPasswordArray);
+    } finally {
+        if (signerKeystoreInputStream != null) {
+            signerKeystoreInputStream.close();
+        }
+    }
     Certificate signerCert = findCert(signerKeystore);
     PrivateKey signerKey = findPrivateKey(signerKeystore, signerPasswordArray);
 
@@ -125,7 +149,15 @@ public class CertUtil {
     keystore.load(null, null);
     keystore.setCertificateEntry(keyName + "Cert", cert);
     keystore.setKeyEntry(keyName + "Key", kp.getPrivate(), password, new Certificate[] {cert, signerCert});
-    keystore.store(new FileOutputStream(targetKeystoreFile), password);
+    FileOutputStream targetKeystoreOutputStream = null;
+    try{
+        targetKeystoreOutputStream = new FileOutputStream(targetKeystoreFile);
+        keystore.store(targetKeystoreOutputStream, password);
+    } finally {
+        if (targetKeystoreOutputStream != null){
+            targetKeystoreOutputStream.close();
+        }
+    }
   }
 
   public static void createSelfSignedCert(String targetKeystoreFileName,
@@ -148,7 +180,15 @@ public class CertUtil {
     keystore.load(null, null);
     keystore.setCertificateEntry(keyName + "Cert", cert);
     keystore.setKeyEntry(keyName + "Key", kp.getPrivate(), password, new Certificate[] {cert});
-    keystore.store(new FileOutputStream(targetKeystoreFile), password);
+    FileOutputStream targetKeystoreOutputStream = null;
+    try{
+        targetKeystoreOutputStream = new FileOutputStream(targetKeystoreFile);
+        keystore.store(targetKeystoreOutputStream, password);
+    } finally {
+        if (targetKeystoreOutputStream != null) {
+            targetKeystoreOutputStream.close();
+        }
+    }
   }
 
   private static KeyPair generateKeyPair() throws NoSuchAlgorithmException {