]> source.dussan.org Git - jgit.git/commitdiff
Close copy threads in case of errors 17/63117/2
authorDmitry Neverov <dmitry.neverov@gmail.com>
Mon, 21 Dec 2015 19:15:42 +0000 (20:15 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 24 Dec 2015 00:20:14 +0000 (01:20 +0100)
Bug: 484775
Change-Id: I3c7105188e615b6b994261f4ece0c8abc98eb444
Signed-off-by: Dmitry Neverov <dmitry.neverov@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java

index 85109a5bf0c02cb3fa043df798928dc07e735546..1dfe5d9797c177c90f0397dd6635e1582d528f19 100644 (file)
@@ -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();