]> source.dussan.org Git - jgit.git/commitdiff
[infer] Fix ObjectWalk leak in PackWriter.preparePack() 27/90227/2
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 2 Feb 2017 23:47:14 +0000 (00:47 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 6 Feb 2017 23:50:09 +0000 (00:50 +0100)
Change-Id: I5d2455404e507faa717e9d916e9b6cd80aa91473
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

index ffab1a74659761fd7caabd03b8b405f1380bf6be..14e4fa6fd78c0989a6fafca43598ffbfd26dcafb 100644 (file)
@@ -745,14 +745,15 @@ public class PackWriter implements AutoCloseable {
                        @NonNull Set<? extends ObjectId> want,
                        @NonNull Set<? extends ObjectId> have,
                        @NonNull Set<? extends ObjectId> 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);
        }
 
        /**