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

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new d1fdfc0  Fix a couple of minor resource leaks
d1fdfc0 is described below

commit d1fdfc00efb789195cc6653cf88c93b8befcfa1e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Apr 17 10:33:59 2020 +0100

    Fix a couple of minor resource leaks
    
    I was experimenting with Eclipse "potential resource leak" warnings and
    found these. There are lots more but quite a few look to be false
    positives.
---
 java/org/apache/catalina/ant/AbstractCatalinaTask.java |  4 +++-
 java/org/apache/catalina/ant/DeployTask.java           | 15 ++++-----------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/ant/AbstractCatalinaTask.java 
b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
index 0d30fe2..c1457af 100644
--- a/java/org/apache/catalina/ant/AbstractCatalinaTask.java
+++ b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
@@ -319,7 +319,9 @@ public abstract class AbstractCatalinaTask extends 
BaseRedirectorHelperTask {
         hconn.connect();
 
         // Swallow response message
-        IOTools.flow(hconn.getInputStream(), null);
+        try (InputStream is = hconn.getInputStream()) {
+            IOTools.flow(is, null);
+        }
     }
 
 
diff --git a/java/org/apache/catalina/ant/DeployTask.java 
b/java/org/apache/catalina/ant/DeployTask.java
index 777f015..a4c54fc 100644
--- a/java/org/apache/catalina/ant/DeployTask.java
+++ b/java/org/apache/catalina/ant/DeployTask.java
@@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.nio.channels.FileChannel;
 import java.util.regex.Pattern;
 
 import org.apache.tools.ant.BuildException;
@@ -139,19 +140,11 @@ public class DeployTask extends 
AbstractCatalinaCommandTask {
                     throw new BuildException(e);
                 }
             } else {
-                FileInputStream fsInput = null;
-                try {
-                    fsInput = new FileInputStream(war);
-                    contentLength = fsInput.getChannel().size();
+                try (FileInputStream fsInput = new FileInputStream(war);
+                        FileChannel fsChannel = fsInput.getChannel()) {
+                    contentLength = fsChannel.size();
                     stream = new BufferedInputStream(fsInput, 1024);
                 } catch (IOException e) {
-                    if (fsInput != null) {
-                        try {
-                            fsInput.close();
-                        } catch (IOException ioe) {
-                            // Ignore
-                        }
-                    }
                     throw new BuildException(e);
                 }
             }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to