[libbluray-devel] FontFactory: avoid leaking font file descriptors

hpi1 git at videolan.org
Wed Aug 27 10:48:45 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Aug 26 13:42:33 2014 +0300| [c059a18956e9f36dddf5b79efcbe56a1a58fdd09] | committer: hpi1

FontFactory: avoid leaking font file descriptors

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

 .../bdj/java-j2se/org/dvb/ui/FontFactory.java      |   28 +++++++++++++++-----
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java b/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java
index eeb6eb9..567e970 100644
--- a/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java
+++ b/src/libbluray/bdj/java-j2se/org/dvb/ui/FontFactory.java
@@ -50,19 +50,35 @@ public class FontFactory {
         fonts = new HashMap(fontIndexData.length);
         for (int i = 0; i < fontIndexData.length; i++) {
             FontIndexData data = fontIndexData[i];
-            FileInputStream inStream = new FileInputStream(BDJUtil.discRootToFilesystem("/BDMV/AUXDATA/" + data.getFileName()));
+            FileInputStream inStream = null;
 
-            Font font = Font.createFont(Font.TRUETYPE_FONT, inStream);
-            font = font.deriveFont(data.getStyle(), data.getMaxSize());
+            try {
+                inStream = new FileInputStream(BDJUtil.discRootToFilesystem("/BDMV/AUXDATA/" + data.getFileName()));
+                Font font = Font.createFont(Font.TRUETYPE_FONT, inStream);
+                font = font.deriveFont(data.getStyle(), data.getMaxSize());
 
-            fonts.put(data.getName(), font);
+                fonts.put(data.getName(), font);
+
+            } finally {
+                if (inStream != null) {
+                    inStream.close();
+                }
+            }
         }
     }
 
     public FontFactory(URL u) throws IOException, FontFormatException {
-        FileInputStream inStream = new FileInputStream(u.getPath());
+        FileInputStream inStream = null;
+
+        try {
+            inStream = new FileInputStream(u.getPath());
+            urlFont = Font.createFont(Font.TRUETYPE_FONT, inStream);
 
-        urlFont = Font.createFont(Font.TRUETYPE_FONT, inStream);
+        } finally {
+            if (inStream != null) {
+                inStream.close();
+            }
+        }
     }
 
     public Font createFont(String name, int style, int size)



More information about the libbluray-devel mailing list