You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/06/01 14:01:04 UTC
[tomcat] branch 9.0.x updated: 64485: Fix possible resource leak
This is an automated email from the ASF dual-hosted git repository.
remm 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 575a2b3 64485: Fix possible resource leak
575a2b3 is described below
commit 575a2b3f3b23474305f3d6333cedda75d600b629
Author: remm <re...@apache.org>
AuthorDate: Mon Jun 1 15:58:02 2020 +0200
64485: Fix possible resource leak
And actually use ConfigurationSource.Resource.getLastModified.
---
java/org/apache/catalina/users/MemoryUserDatabase.java | 2 +-
java/org/apache/tomcat/util/file/ConfigurationSource.java | 11 ++++++++++-
webapps/docs/changelog.xml | 4 ++++
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/catalina/users/MemoryUserDatabase.java b/java/org/apache/catalina/users/MemoryUserDatabase.java
index 6062c75..a9d3fc8 100644
--- a/java/org/apache/catalina/users/MemoryUserDatabase.java
+++ b/java/org/apache/catalina/users/MemoryUserDatabase.java
@@ -425,7 +425,7 @@ public class MemoryUserDatabase implements UserDatabase {
String pathName = getPathname();
try (ConfigurationSource.Resource resource = ConfigFileLoader.getSource().getResource(pathName)) {
- this.lastModified = resource.getURI().toURL().openConnection().getLastModified();
+ lastModified = resource.getLastModified();
// Construct a digester to read the XML input file
Digester digester = new Digester();
diff --git a/java/org/apache/tomcat/util/file/ConfigurationSource.java b/java/org/apache/tomcat/util/file/ConfigurationSource.java
index 2df11bc..57d5ce4 100644
--- a/java/org/apache/tomcat/util/file/ConfigurationSource.java
+++ b/java/org/apache/tomcat/util/file/ConfigurationSource.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
+import java.net.URLConnection;
/**
* Abstracts configuration file storage. Allows Tomcat embedding using the regular
@@ -92,7 +93,15 @@ public interface ConfigurationSource {
}
public long getLastModified()
throws MalformedURLException, IOException {
- return uri.toURL().openConnection().getLastModified();
+ URLConnection connection = null;
+ try {
+ connection = uri.toURL().openConnection();
+ return connection.getLastModified();
+ } finally {
+ if (connection != null) {
+ connection.getInputStream().close();
+ }
+ }
}
@Override
public void close() throws IOException {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a5e3266..dc7b498 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -91,6 +91,10 @@
Expose server certificate through the <code>SSLSupport</code>
interface. (remm)
</update>
+ <fix>
+ <bug>64485</bug>: Fix possible resource leak geting last modified from
+ <code>ConfigurationSource.Resource</code>. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="WebSocket">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org