[libbluray-devel] [fix][java] Close resources after use.

ace20022 git at videolan.org
Fri Nov 28 10:24:05 CET 2014


libbluray | branch: master | ace20022 <ace20022 at ymail.com> | Thu Nov 27 13:19:35 2014 +0100| [ce5cf46929292c35e2af951efff502d40cdeda50] | committer: hpi1

[fix][java] Close resources after use.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=ce5cf46929292c35e2af951efff502d40cdeda50
---

 src/libbluray/bdj/java-j2se/org/videolan/LockFile.java |   11 ++++++++++-
 src/libbluray/bdj/java/org/videolan/Copy.java          |    4 +++-
 src/libbluray/bdj/java/org/videolan/MountManager.java  |    7 +++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/libbluray/bdj/java-j2se/org/videolan/LockFile.java b/src/libbluray/bdj/java-j2se/org/videolan/LockFile.java
index 2d347cd..31ca4fe 100644
--- a/src/libbluray/bdj/java-j2se/org/videolan/LockFile.java
+++ b/src/libbluray/bdj/java-j2se/org/videolan/LockFile.java
@@ -30,8 +30,9 @@ class LockFile {
 
     public static LockFile create(String path) {
 
+        RandomAccessFile os = null;
         try {
-            RandomAccessFile os = new RandomAccessFile(path, "rw");
+            os = new RandomAccessFile(path, "rw");
             if (os.getChannel().tryLock() != null) {
                 /* Test if locking works: second tryLock() should fail */
                 if (os.getChannel().tryLock() != null) {
@@ -44,9 +45,17 @@ class LockFile {
                 }
                 return new LockFile(os);
             } else {
+                os.close();
                 logger.info("Failed locking " + path);
             }
         } catch (Exception e) {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException e1) {
+                    e1.printStackTrace();
+                }
+            }
             logger.error("Failed creating lock file: " + e);
         }
         return null;
diff --git a/src/libbluray/bdj/java/org/videolan/Copy.java b/src/libbluray/bdj/java/org/videolan/Copy.java
index ea48ae0..353fee7 100644
--- a/src/libbluray/bdj/java/org/videolan/Copy.java
+++ b/src/libbluray/bdj/java/org/videolan/Copy.java
@@ -41,7 +41,9 @@ public class Copy {
         }
 
         ClObjectInputStream ios = new ClObjectInputStream(cl, new ByteArrayInputStream(bos.toByteArray()));
-        return (Serializable)ios.readObject();
+        Serializable s = (Serializable)ios.readObject();
+        ios.close();
+        return s;
     }
 
     /* ObjectInputStream with xlet class loader */
diff --git a/src/libbluray/bdj/java/org/videolan/MountManager.java b/src/libbluray/bdj/java/org/videolan/MountManager.java
index dfa16c8..6514de8 100644
--- a/src/libbluray/bdj/java/org/videolan/MountManager.java
+++ b/src/libbluray/bdj/java/org/videolan/MountManager.java
@@ -76,6 +76,13 @@ public class MountManager {
             }
         } catch (IOException e) {
             e.printStackTrace();
+            if (jar != null) {
+                try {
+                    jar.close();
+                } catch (IOException e1) {
+                    e1.printStackTrace();
+                }
+            }
             throw new MountException();
         }
 



More information about the libbluray-devel mailing list