From fbcc2cb4ca6b1732e28edeb766b8d57e2de560ce Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sun, 18 Dec 2016 01:33:58 +0100 Subject: [PATCH] [infer] Fix resource leaks in SubmoduleAddCommand Bug: 509385 Change-Id: I9d25cf117cfb19df108f5fe281232193fd898474 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/api/SubmoduleAddCommand.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java index fbb24c157..b0f772e0a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java @@ -133,7 +133,9 @@ public SubmoduleAddCommand setProgressMonitor(final ProgressMonitor monitor) { */ protected boolean submoduleExists() throws IOException { TreeFilter filter = PathFilter.create(path); - return SubmoduleWalk.forIndex(repo).setFilter(filter).next(); + try (SubmoduleWalk w = SubmoduleWalk.forIndex(repo)) { + return w.setFilter(filter).next(); + } } /** @@ -178,7 +180,11 @@ public Repository call() throws GitAPIException { clone.setURI(resolvedUri); if (monitor != null) clone.setProgressMonitor(monitor); - Repository subRepo = clone.call().getRepository(); + Repository subRepo = null; + try (Git git = clone.call()) { + subRepo = git.getRepository(); + subRepo.incrementOpen(); + } // Save submodule URL to parent repository's config StoredConfig config = repo.getConfig();