From 08480c948c47b905ace6ecec43ae0c92a218d1d6 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 3 Feb 2017 00:47:14 +0100 Subject: [PATCH] [infer] Fix ObjectWalk leak in PackWriter.preparePack() Change-Id: I5d2455404e507faa717e9d916e9b6cd80aa91473 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 ffab1a7465..14e4fa6fd7 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 @@ -745,14 +745,15 @@ public class PackWriter implements AutoCloseable { @NonNull Set want, @NonNull Set have, @NonNull Set shallow) throws IOException { - ObjectWalk ow; - if (shallowPack) { - ow = new DepthWalk.ObjectWalk(reader, depth - 1); - } else { - ow = new ObjectWalk(reader); + try (ObjectWalk ow = getObjectWalk()) { + ow.assumeShallow(shallow); + preparePack(countingMonitor, ow, want, have); } - ow.assumeShallow(shallow); - preparePack(countingMonitor, ow, want, have); + } + + private ObjectWalk getObjectWalk() { + return shallowPack ? new DepthWalk.ObjectWalk(reader, depth - 1) + : new ObjectWalk(reader); } /** -- 2.39.5