]> source.dussan.org Git - jgit.git/commitdiff
ObjectWalk: close ObjectReader on close() if needed 85/190185/2
authorThomas Wolf <thomas.wolf@paranor.ch>
Sun, 30 Jan 2022 21:15:14 +0000 (22:15 +0100)
committerThomas Wolf <thomas.wolf@paranor.ch>
Sun, 30 Jan 2022 21:18:30 +0000 (22:18 +0100)
If the walk is created via ObjectWalk(Repository), it creates a new
ObjectReader. This reader was closed only on dispose(). If such an
ObjectWalk was used in a try-with-resource statement the reader might
not get closed.

Bug: 578458
Change-Id: I1be31829dc466530f23006a53c29b657fd5fb410
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

index e6f9580bf79ad2d94070ef74cfe43acc28071388..4e48a5c3286665de05708cc9b6ac5d4f316ad7a4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -139,7 +139,7 @@ public class ObjectWalk extends RevWalk {
         *            the repository the walker will obtain data from.
         */
        public ObjectWalk(Repository repo) {
-               this(repo.newObjectReader());
+               this(repo.newObjectReader(), true);
        }
 
        /**
@@ -151,7 +151,11 @@ public class ObjectWalk extends RevWalk {
         *            required.
         */
        public ObjectWalk(ObjectReader or) {
-               super(or);
+               this(or, false);
+       }
+
+       private ObjectWalk(ObjectReader or, boolean closeReader) {
+               super(or, closeReader);
                setRetainBody(false);
                rootObjects = new ArrayList<>();
                pendingObjects = new BlockObjQueue();
index 8d571f5b1444f1459307c2b257a3ceaf58b4a25e..a50eaf1a8afb4687a1f20f85acab76cf2a10f66c 100644 (file)
@@ -215,7 +215,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
                this(or, false);
        }
 
-       private RevWalk(ObjectReader or, boolean closeReader) {
+       RevWalk(ObjectReader or, boolean closeReader) {
                reader = or;
                idBuffer = new MutableObjectId();
                objects = new ObjectIdOwnerMap<>();