From: Matthias Sohn Date: Thu, 2 Feb 2017 23:47:14 +0000 (+0100) Subject: [infer] Fix ObjectWalk leak in PackWriter.preparePack() X-Git-Tag: v4.7.0.201704051617-r~87 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08480c948c47b905ace6ecec43ae0c92a218d1d6;p=jgit.git [infer] Fix ObjectWalk leak in PackWriter.preparePack() Change-Id: I5d2455404e507faa717e9d916e9b6cd80aa91473 Signed-off-by: Matthias Sohn --- 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); } /**