Browse Source

Fix file handle leak in FetchCommand#fetchSubmodules

The private fetchSubmodules method in the FetchCommand class creates a
Repository instance for each submodule being fetched, but never calls
closes on it.

This leads to the leaking of file handles.

Bug: 526494
Change-Id: I7070388b8b62063d9d5cd31afae3015a8388044f
Signed-off-by: Tim Hosey <timhoseydev@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.11
Tim Hosey 7 years ago committed by Matthias Sohn
parent
commit
67a8858b94
  1. 12
      org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java

12
org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java

@ -171,7 +171,7 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> {
} }
walk.setTree(revWalk.parseTree(fetchHead)); walk.setTree(revWalk.parseTree(fetchHead));
while (walk.next()) { while (walk.next()) {
Repository submoduleRepo = walk.getRepository(); try (Repository submoduleRepo = walk.getRepository()) {
// Skip submodules that don't exist locally (have not been // Skip submodules that don't exist locally (have not been
// cloned), are not registered in the .gitmodules file, or // cloned), are not registered in the .gitmodules file, or
@ -184,15 +184,18 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> {
FetchRecurseSubmodulesMode recurseMode = getRecurseMode( FetchRecurseSubmodulesMode recurseMode = getRecurseMode(
walk.getPath()); walk.getPath());
// When the fetch mode is "yes" we always fetch. When the mode // When the fetch mode is "yes" we always fetch. When the
// is "on demand", we only fetch if the submodule's revision was // mode
// is "on demand", we only fetch if the submodule's revision
// was
// updated to an object that is not currently present in the // updated to an object that is not currently present in the
// submodule. // submodule.
if ((recurseMode == FetchRecurseSubmodulesMode.ON_DEMAND if ((recurseMode == FetchRecurseSubmodulesMode.ON_DEMAND
&& !submoduleRepo.hasObject(walk.getObjectId())) && !submoduleRepo.hasObject(walk.getObjectId()))
|| recurseMode == FetchRecurseSubmodulesMode.YES) { || recurseMode == FetchRecurseSubmodulesMode.YES) {
FetchCommand f = new FetchCommand(submoduleRepo) FetchCommand f = new FetchCommand(submoduleRepo)
.setProgressMonitor(monitor).setTagOpt(tagOption) .setProgressMonitor(monitor)
.setTagOpt(tagOption)
.setCheckFetchedObjects(checkFetchedObjects) .setCheckFetchedObjects(checkFetchedObjects)
.setRemoveDeletedRefs(isRemoveDeletedRefs()) .setRemoveDeletedRefs(isRemoveDeletedRefs())
.setThin(thin).setRefSpecs(refSpecs) .setThin(thin).setRefSpecs(refSpecs)
@ -205,6 +208,7 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> {
results.addSubmodule(walk.getPath(), f.call()); results.addSubmodule(walk.getPath(), f.call());
} }
} }
}
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} catch (ConfigInvalidException e) { } catch (ConfigInvalidException e) {

Loading…
Cancel
Save