You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/04/17 09:35:22 UTC
[tomcat] branch 9.0.x updated: Fix a couple of minor resource leaks
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 14df7eb Fix a couple of minor resource leaks
14df7eb is described below
commit 14df7ebf327deb2b9c63d2867666dfe1f80e0179
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org