[infer] Fix resource leaks in SubmoduleAddCommand

Bug: 509385
Change-Id: I9d25cf117cfb19df108f5fe281232193fd898474
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2016-12-18 01:33:58 +01:00
parent 82344bd7a2
commit fbcc2cb4ca
1 changed files with 8 additions and 2 deletions

View File

@ -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();