Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2016-12-19 07:45:49 +0000
committerMatthias Sohn2016-12-21 22:51:50 +0000
commit1fb2319c188d68412c40189d298e51f62c899944 (patch)
tree80eef628d5b514855ad7fd0d772d0b6c1a01c750
parent325cb35ccd6108eaf9e6c3ec6343ca6988f10a21 (diff)
downloadjgit-1fb2319c188d68412c40189d298e51f62c899944.tar.gz
jgit-1fb2319c188d68412c40189d298e51f62c899944.tar.xz
jgit-1fb2319c188d68412c40189d298e51f62c899944.zip
[infer] Fix resource leak in IndexDiff
We only need the tree id to add it to a TreeWalk so change tree's type to AnyObjectId. Bug: 509385 Change-Id: I98dd5fef15cd173fe1fd84273f0f48e64e12e608 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index 1863692834..af6a4fb919 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -65,7 +65,6 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StopWalkException;
import org.eclipse.jgit.internal.JGitText;
-import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.submodule.SubmoduleWalk;
import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
@@ -248,7 +247,7 @@ public class IndexDiff {
private final Repository repository;
- private final RevTree tree;
+ private final AnyObjectId tree;
private TreeFilter filter = null;
@@ -311,10 +310,13 @@ public class IndexDiff {
public IndexDiff(Repository repository, ObjectId objectId,
WorkingTreeIterator workingTreeIterator) throws IOException {
this.repository = repository;
- if (objectId != null)
- tree = new RevWalk(repository).parseTree(objectId);
- else
+ if (objectId != null) {
+ try (RevWalk rw = new RevWalk(repository)) {
+ tree = rw.parseTree(objectId);
+ }
+ } else {
tree = null;
+ }
this.initialWorkingTreeIterator = workingTreeIterator;
}

Back to the top