From 80113c7bb65c4c624250e430b5f2b19b1367d18c Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Sat, 16 Jun 2012 00:19:51 +0200 Subject: Fix resource leaks due to unclosed repositories Whenever a call to JGit returns a Repository the caller should make sure to call close() on it if he doesn't need it anymore. Since instances of Repository contain e.g. open FileOutputStreams (for pack files) forgetting to close the repository can lead to resource leaks. This was the reason why dozens of the JUnit tests failed on Windows with "Can't delete file ...." errors. In LocalDiskRepositoryTestCase.tearDown() we tried to delete the repositories we used during tests which failed because we had open FileOutputStreams. Not only the obvious cases during Clone or Init operations returned Repositories, but also the new SubModule API created repository instances. In some places we even forgot to close submodule repositories in our internal coding. To see the effects of this fix run the JGit JUnit tests under Windows. On other platforms it's harder to see because either the leaking resources don't lead to failing JUnit tests (on Unix you can delete files with open FileOutputStreams) or the java gc runs differently and cleans up the resources earlier. Change-Id: I6d4f637b0d4af20ff4d501db091548696373a58a Signed-off-by: Christian Halstrick Signed-off-by: Matthias Sohn --- org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'org.eclipse.jgit.ant/src/org/eclipse') diff --git a/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java b/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java index 8d12ce3ad4..f23f3b753d 100644 --- a/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java +++ b/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java @@ -109,7 +109,7 @@ public class GitCloneTask extends Task { CloneCommand clone = Git.cloneRepository(); try { clone.setURI(uri).setDirectory(destination).setBranch(branch).setBare(bare); - clone.call(); + clone.call().getRepository().close(); } catch (Exception e) { log("Could not clone repository: " + e, e, Project.MSG_ERR); throw new BuildException("Could not clone repository: " + e.getMessage(), e); -- cgit v1.2.3