pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tboe...@apache.org
Subject svn commit: r1705711 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
Date Mon, 28 Sep 2015 15:54:22 GMT
Author: tboehme
Date: Mon Sep 28 15:54:22 2015
New Revision: 1705711

URL: http://svn.apache.org/viewvc?rev=1705711&view=rev
Log:
PDFBOX-2883: ensure ScratchFileBuffer is closed (using finalize) in order to cope with sloppy
usage in COSStream and to ensure buffers are freed if no needed anymore

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java?rev=1705711&r1=1705710&r2=1705711&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFileBuffer.java Mon Sep
28 15:54:22 2015
@@ -19,6 +19,10 @@ package org.apache.pdfbox.io;
 import java.io.EOFException;
 import java.io.IOException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.cos.COSStream;
+
 /**
  * Implementation of {@link RandomAccess} as sequence of multiple fixed size pages handled
  * by {@link ScratchFile}.
@@ -60,6 +64,8 @@ class ScratchFileBuffer implements Rando
     /** number of pages held by this buffer */
     private int pageCount = 0;
     
+    private static final Log LOG = LogFactory.getLog(ScratchFileBuffer.class);
+    
     /**
      * Creates a new buffer using pages handled by provided {@link ScratchFile}.
      * 
@@ -489,4 +495,24 @@ class ScratchFileBuffer implements Rando
             size = 0;
         }
     }
+    
+    /**
+     * While calling finalize is normally discouraged we will have to
+     * use it here as long as closing a scratch file buffer is not 
+     * done in every case. Currently {@link COSStream} creates new
+     * buffers without closing the old one - which might still be
+     * used.
+     * 
+     * <p>Enabling debugging one will see if there are still cases
+     * where the buffer is not closed.</p>
+     */
+    @Override
+    protected void finalize() throws Throwable
+    {
+        if ((pageHandler != null) && LOG.isDebugEnabled())
+        {
+            LOG.debug("ScratchFileBuffer not closed!");
+        }
+        close();
+    }
 }



Mime
View raw message