diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2016-12-19 08:45:49 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2016-12-21 23:51:50 +0100 |
commit | 1fb2319c188d68412c40189d298e51f62c899944 (patch) | |
tree | 80eef628d5b514855ad7fd0d772d0b6c1a01c750 /org.eclipse.jgit | |
parent | 325cb35ccd6108eaf9e6c3ec6343ca6988f10a21 (diff) | |
download | jgit-1fb2319c188d68412c40189d298e51f62c899944.tar.gz 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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java | 12 |
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; } |