Browse Source

[infer] Fix resource leak in RepoCommand

Bug: 509385
Change-Id: I30c427f0dd2fc1fceb6b003dfdee0a05efaefca9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.6
Matthias Sohn 8 years ago
parent
commit
e78626f414
  1. 12
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java

12
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) public byte[] readFile(String uri, String ref, String path)
throws GitAPIException, IOException { throws GitAPIException, IOException {
File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
Repository repo = Git try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
.cloneRepository() .setURI(uri).call();
.setBare(true) Repository repo = git.getRepository()) {
.setDirectory(dir)
.setURI(uri)
.call()
.getRepository();
try {
return readFileFromRepo(repo, ref, path); return readFileFromRepo(repo, ref, path);
} finally { } finally {
repo.close();
FileUtils.delete(dir, FileUtils.RECURSIVE); FileUtils.delete(dir, FileUtils.RECURSIVE);
} }
} }

Loading…
Cancel
Save