diff options
author | Stefan Bodewig <bodewig@apache.org> | 2022-04-09 17:58:33 +0200 |
---|---|---|
committer | Stefan Bodewig <bodewig@apache.org> | 2022-04-09 17:58:33 +0200 |
commit | 2989738c90eca6d6d7ebadf8b430b0123858539a (patch) | |
tree | 4d4b1aa658aa7226aae5df7ef2f7ff07cd909bf7 /src | |
parent | c6854c58adb0ba436ddb86c7d7601faf2de9e532 (diff) | |
download | ant-2989738c90eca6d6d7ebadf8b430b0123858539a.tar.gz |
plug resource leak as suggested by Mike Phillips in BZ issue 66001
Diffstat (limited to 'src')
-rw-r--r-- | src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java | 14 |
1 files changed, 9 insertions, 5 deletions
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 |