Skip to content

Commit 8033f16

Browse files
author
Maruan Sahyoun
committed
PDFBOX-5660: create RandomAccessOutputStream within try clause
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1932932 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1fcb871 commit 8033f16

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,12 @@ public OutputStream createOutputStream(COSBase filters) throws IOException
230230
randomAccess.clear();
231231
else
232232
randomAccess = getStreamCache().createBuffer();
233-
OutputStream randomOut = new RandomAccessOutputStream(randomAccess);
234-
boolean success = false;
233+
OutputStream randomOut = null;
235234

236235
try
237236
{
237+
randomOut = new RandomAccessOutputStream(randomAccess);
238+
238239
OutputStream cosOut = new COSOutputStream(getFilterList(), this, randomOut,
239240
getStreamCache());
240241
isWriting = true;
@@ -254,12 +255,12 @@ public void close() throws IOException
254255
isWriting = false;
255256
}
256257
};
257-
success = true;
258+
randomOut = null; // ownership transferred to result, so don't close it in the finally block
258259
return result;
259260
}
260261
finally
261262
{
262-
if (!success)
263+
if (randomOut != null)
263264
{
264265
// clean up partially written data
265266
randomOut.close();

0 commit comments

Comments
 (0)