You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2022/04/09 15:59:15 UTC

[ant] branch 1.9.x updated: plug resource leak as suggested by Mike Phillips in BZ issue 66001

This is an automated email from the ASF dual-hosted git repository.

bodewig pushed a commit to branch 1.9.x
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/1.9.x by this push:
     new 2989738c9 plug resource leak as suggested by Mike Phillips in BZ issue 66001
2989738c9 is described below

commit 2989738c90eca6d6d7ebadf8b430b0123858539a
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sat Apr 9 17:58:33 2022 +0200

    plug resource leak as suggested by Mike Phillips in BZ issue 66001
---
 WHATSNEW                                                   | 14 +++++++++-----
 .../tools/ant/taskdefs/optional/ssh/ScpFromMessage.java    | 14 +++++++++-----
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/WHATSNEW b/WHATSNEW
index 3c207a8e2..0f69bd28b 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -4,11 +4,11 @@ Changes from Ant 1.9.16 TO Ant 1.9.17
 Changes that could break older environments:
 --------------------------------------------
 
-* <get> has a new attribute authenticateOnRedirect that can be used to
-  prevent Ant from sending the configured credentials when following a
-  redirect. It is false by default, which means builds that rely on
-  credentials being used on the redirected URI may break.
-  Github Pull Request #173
+ * <get> has a new attribute authenticateOnRedirect that can be used to
+   prevent Ant from sending the configured credentials when following a
+   redirect. It is false by default, which means builds that rely on
+   credentials being used on the redirected URI may break.
+   Github Pull Request #173
 
 Fixed bugs:
 -----------
@@ -18,6 +18,10 @@ Fixed bugs:
    the shorter alias names.
    Bugzilla Report 65539
 
+ * <scp> may leak connections when trying to preserve the las modified
+   timestamps of files transferred recursively from a server.
+   Bugzilla Report 66001
+
 Other changes:
 --------------
 
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
index bce3f78a9..96be3447f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
@@ -310,12 +310,16 @@ public class ScpFromMessage extends AbstractSshMessage {
     private void setLastModified(final File localFile) throws JSchException {
         SftpATTRS fileAttributes = null;
         final ChannelSftp channel = openSftpChannel();
-        channel.connect();
         try {
-            fileAttributes = channel.lstat(remoteDir(remoteFile)
-                                           + localFile.getName());
-        } catch (final SftpException e) {
-            throw new JSchException("failed to stat remote file", e);
+            channel.connect();
+            try {
+                fileAttributes = channel.lstat(remoteDir(remoteFile)
+                                               + localFile.getName());
+            } catch (final SftpException e) {
+                throw new JSchException("failed to stat remote file", e);
+            }
+        } finally {
+            channel.disconnect();
         }
         FileUtils.getFileUtils().setFileLastModified(localFile,
                                                      ((long) fileAttributes