From f30fe13ac94df9de77c18813f41c29fe7f55a44f Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 19 Dec 2016 08:38:41 +0100 Subject: [PATCH] [infer] Fix a resource leak in PackWriter Bug: 509385 Change-Id: Ic8a82895fa39be73f1bd8427cfe9437be6fc4e3e Signed-off-by: Matthias Sohn --- .../jgit/internal/storage/pack/PackWriter.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 691867aba..8b4d2e6d3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -1597,14 +1597,15 @@ public class PackWriter implements AutoCloseable { } } - TemporaryBuffer.Heap delta = delta(otp); - out.writeHeader(otp, delta.length()); + try (TemporaryBuffer.Heap delta = delta(otp)) { + out.writeHeader(otp, delta.length()); - Deflater deflater = deflater(); - deflater.reset(); - DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); - delta.writeTo(dst, null); - dst.finish(); + Deflater deflater = deflater(); + deflater.reset(); + DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); + delta.writeTo(dst, null); + dst.finish(); + } typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); }