From: Dmitry Neverov Date: Mon, 21 Dec 2015 19:15:42 +0000 (+0100) Subject: Close copy threads in case of errors X-Git-Tag: v4.2.0.201601211800-r~4^2~58 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F63117%2F2;p=jgit.git Close copy threads in case of errors Bug: 484775 Change-Id: I3c7105188e615b6b994261f4ece0c8abc98eb444 Signed-off-by: Dmitry Neverov --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java index 85109a5bf0..1dfe5d9797 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java @@ -149,14 +149,27 @@ public class JschSession implements RemoteSession { channel.setCommand(commandName); setupStreams(); channel.connect(timeout > 0 ? timeout * 1000 : 0); - if (!channel.isConnected()) + if (!channel.isConnected()) { + closeOutputStream(); throw new TransportException(uri, JGitText.get().connectionFailed); + } } catch (JSchException e) { + closeOutputStream(); throw new TransportException(uri, e.getMessage(), e); } } + private void closeOutputStream() { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException ioe) { + // ignore + } + } + } + private void setupStreams() throws IOException { inputStream = channel.getInputStream();