Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick2012-06-15 22:19:51 +0000
committerMatthias Sohn2012-06-15 22:19:51 +0000
commit80113c7bb65c4c624250e430b5f2b19b1367d18c (patch)
treee3bc527bf93014d3d4f577c60bd6a7e559374012 /org.eclipse.jgit.ant
parentc745c93e40abdad7afde4e3b48dbb11469916112 (diff)
downloadjgit-80113c7bb65c4c624250e430b5f2b19b1367d18c.tar.gz
jgit-80113c7bb65c4c624250e430b5f2b19b1367d18c.tar.xz
jgit-80113c7bb65c4c624250e430b5f2b19b1367d18c.zip
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 <christian.halstrick@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.ant')
-rw-r--r--org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCloneTask.java2
1 files changed, 1 insertions, 1 deletions
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);

Back to the top