pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1704700 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
Date Tue, 22 Sep 2015 19:22:31 GMT
Author: tilman
Date: Tue Sep 22 19:22:29 2015
New Revision: 1704700

URL: http://svn.apache.org/viewvc?rev=1704700&view=rev
Log:
PDFBOX-2986: avoid potential resource leak

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1704700&r1=1704699&r2=1704700&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
Tue Sep 22 19:22:29 2015
@@ -53,6 +53,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.encoding.MacOSRomanEncoding;
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.PDStream;
@@ -453,6 +454,7 @@ public class PDTrueTypeFont extends PDSi
     /**
      * {@inheritDoc}
      */
+    @Override
     public Font getawtFont() throws IOException
     {
          PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary)getFontDescriptor();
@@ -461,10 +463,12 @@ public class PDTrueTypeFont extends PDSi
             PDStream ff2Stream = fd.getFontFile2();
             if( ff2Stream != null )
             {
+                InputStream is = null;
                 try
                 {
                     // create a font with the embedded data
-                    awtFont = Font.createFont( Font.TRUETYPE_FONT, ff2Stream.createInputStream()
);
+                    is = ff2Stream.createInputStream();
+                    awtFont = Font.createFont(Font.TRUETYPE_FONT, is);
                 }
                 catch( FontFormatException f )
                 {
@@ -483,6 +487,10 @@ public class PDTrueTypeFont extends PDSi
                         log.info("Can't read the embedded font " + fd.getFontName() );
                     }
                 }
+                finally
+                {
+                    IOUtils.closeQuietly(is);
+                }
                 if (awtFont == null)
                 {
                     if (fd.getFontName() != null)



Mime
View raw message