diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-02-06 20:46:09 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-02-06 20:58:44 +0000 |
commit | d9442b1398117ee1710a608a7c30d5e1a073a945 (patch) | |
tree | 2f41e57886e3bb261b1268feb0860bd8ddaa9621 /xmerge | |
parent | 2b198c3380ccf07aa981a055eff698e1482028c8 (diff) |
coverity#1326516 Resource leak on an exceptional path
Change-Id: Ia46ec73bd3dcaef1ec0c9a977f3fc472d94ed390
Diffstat (limited to 'xmerge')
-rw-r--r-- | xmerge/source/xmerge/java/org/openoffice/xmerge/test/Driver.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/test/Driver.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/test/Driver.java index 7e970334d9b2..9d3ae7cb00a7 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/test/Driver.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/test/Driver.java @@ -100,6 +100,15 @@ public final class Driver { } } + private static void close(FileOutputStream c) { + if (c == null) return; + try { + c.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * Gets a {@code Convert} object using the {@code ConverterFactory} and does * the conversion using this object. @@ -153,15 +162,17 @@ public final class Driver { while (docEnum.hasNext()) { Document docOut = (Document)docEnum.next(); String fileName = docOut.getFileName(); + FileOutputStream fos = null; try { - FileOutputStream fos = new FileOutputStream(fileName); + fos = new FileOutputStream(fileName); docOut.write(fos); fos.flush(); - fos.close(); } catch (Exception writeExcept) { System.out.println("\nThere was an writing out file <" + fileName + ">"); writeExcept.printStackTrace(); + } finally { + close(fos); } } } else { |