Repository: incubator-slider
Updated Branches:
  refs/heads/develop de725c240 -> 481bd3209


SLIDER-1152 Resource leaks found in code


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

Branch: refs/heads/develop
Commit: 481bd3209d6064eb913c0e21779a427fb49216b8
Parents: de725c2
Author: Gour Saha <gourks...@apache.org>
Authored: Sun Jul 24 10:00:33 2016 -0700
Committer: Gour Saha <gourks...@apache.org>
Committed: Sun Jul 24 10:01:38 2016 -0700

----------------------------------------------------------------------
 .../apache/slider/api/proto/RestTypeMarshalling.java | 14 +++++++++-----
 .../java/org/apache/slider/client/SliderClient.java  | 15 +++++++++++----
 .../apache/slider/core/launch/CredentialUtils.java   |  7 +++++--
 3 files changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/481bd320/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java
 
b/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java
index 766ee83..17fd965 100644
--- 
a/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java
+++ 
b/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java
@@ -105,13 +105,17 @@ public class RestTypeMarshalling {
     return builder.build();
   }
 
-  @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
   private static byte[] getStoreBytes(SecurityStore securityStore)
       throws IOException {
-    InputStream is = new FileInputStream(securityStore.getFile());
-    byte[] storeBytes = IOUtils.toByteArray(is);
-    if (is != null) {
-      is.close();
+    InputStream is = null;
+    byte[] storeBytes;
+    try {
+      is = new FileInputStream(securityStore.getFile());
+      storeBytes = IOUtils.toByteArray(is);
+    } finally {
+      if (is != null) {
+        is.close();
+      }
     }
     return storeBytes;
   }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/481bd320/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java 
b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index 288cff3..f3dcea3 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -1181,10 +1181,17 @@ public class SliderClient extends 
AbstractSliderLaunchedService implements RunSe
     byte[] keystore = createClusterOperations(clientInfo.name)
         .getClientCertificateStore(hostname, "client", password, type.name());
     // persist to file
-    FileOutputStream storeFileOutputStream = new FileOutputStream(storeFile);
-    IOUtils.write(keystore, storeFileOutputStream);
-    if (storeFileOutputStream != null) {
-      storeFileOutputStream.close();
+    FileOutputStream storeFileOutputStream = null;
+    try {
+      storeFileOutputStream = new FileOutputStream(storeFile);
+      IOUtils.write(keystore, storeFileOutputStream);
+    } catch (Exception e) {
+      log.error("Unable to persist to file {}", storeFile);
+      throw e;
+    } finally {
+      if (storeFileOutputStream != null) {
+        storeFileOutputStream.close();
+      }
     }
 
     return EXIT_SUCCESS;

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/481bd320/slider-core/src/main/java/org/apache/slider/core/launch/CredentialUtils.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/core/launch/CredentialUtils.java 
b/slider-core/src/main/java/org/apache/slider/core/launch/CredentialUtils.java
index 255890b..5357cc4 100644
--- 
a/slider-core/src/main/java/org/apache/slider/core/launch/CredentialUtils.java
+++ 
b/slider-core/src/main/java/org/apache/slider/core/launch/CredentialUtils.java
@@ -87,8 +87,11 @@ public final class CredentialUtils {
     ByteBuffer buffer = null;
     if (!credentials.getAllTokens().isEmpty()) {
       DataOutputBuffer dob = new DataOutputBuffer();
-      credentials.writeTokenStorageToStream(dob);
-      dob.close();
+      try {
+        credentials.writeTokenStorageToStream(dob);
+      } finally {
+        dob.close();
+      }
       buffer = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
     }
     return buffer;

Reply via email to