]> source.dussan.org Git - jgit.git/commitdiff
[infer] Fix resource leak in RepoCommand 67/87367/5
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 18 Dec 2016 00:54:51 +0000 (01:54 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 18 Dec 2016 22:02:45 +0000 (23:02 +0100)
Bug: 509385
Change-Id: I30c427f0dd2fc1fceb6b003dfdee0a05efaefca9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java

index 9b7f094d0f2638451f01233cc29ce74de8df9584..86dbabca0b9c9b61f850b9fe2d8a63e1ffe9e0bd 100644 (file)
@@ -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);
                        }
                }