summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2016-12-18 01:54:51 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2016-12-18 23:02:45 +0100
commite78626f4140742bdffaca3689dbf1963d5dd30f3 (patch)
tree2340b0d4f1dc807d9ad2f48b72ca197a8afc07c6 /org.eclipse.jgit/src
parent1779fb4a57375bbb3e92246a47c63a846af90491 (diff)
downloadjgit-e78626f4140742bdffaca3689dbf1963d5dd30f3.tar.gz
jgit-e78626f4140742bdffaca3689dbf1963d5dd30f3.zip
[infer] Fix resource leak in RepoCommand
Bug: 509385 Change-Id: I30c427f0dd2fc1fceb6b003dfdee0a05efaefca9 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java12
1 files changed, 3 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
index 9b7f094d0f..86dbabca0b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
@@ -180,17 +180,11 @@ public class RepoCommand extends GitCommand<RevCommit> {
public byte[] readFile(String uri, String ref, String path)
throws GitAPIException, IOException {
File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
- Repository repo = Git
- .cloneRepository()
- .setBare(true)
- .setDirectory(dir)
- .setURI(uri)
- .call()
- .getRepository();
- try {
+ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
+ .setURI(uri).call();
+ Repository repo = git.getRepository()) {
return readFileFromRepo(repo, ref, path);
} finally {
- repo.close();
FileUtils.delete(dir, FileUtils.RECURSIVE);
}
}