From cc0d58f9a0e3d3dc5c1eb49f33e3a061f2f3caf5 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Tue, 11 Oct 2016 14:17:46 +0200 Subject: [PATCH] AmazonS3: ensure that errorStream is closed Change-Id: I2abde5dbd4b785d70b7bc0b77188c0a075130eeb Signed-off-by: Matthias Sohn --- .../org/eclipse/jgit/transport/AmazonS3.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index 4069a64535..1aebaddacd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -529,21 +529,29 @@ public class AmazonS3 { Integer.valueOf(HttpSupport.response(c)), c.getResponseMessage())); final InputStream errorStream = c.getErrorStream(); - if (errorStream == null) + if (errorStream == null) { return err; + } - final ByteArrayOutputStream b = new ByteArrayOutputStream(); - byte[] buf = new byte[2048]; - for (;;) { - final int n = errorStream.read(buf); - if (n < 0) - break; - if (n > 0) - b.write(buf, 0, n); + try { + final ByteArrayOutputStream b = new ByteArrayOutputStream(); + byte[] buf = new byte[2048]; + for (;;) { + final int n = errorStream.read(buf); + if (n < 0) { + break; + } + if (n > 0) { + b.write(buf, 0, n); + } + } + buf = b.toByteArray(); + if (buf.length > 0) { + err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$ + } + } finally { + errorStream.close(); } - buf = b.toByteArray(); - if (buf.length > 0) - err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$ return err; } -- 2.39.5