tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [tomcat] branch master updated: 64485: Fix possible resource leak
Date Mon, 01 Jun 2020 13:58:24 GMT
This is an automated email from the ASF dual-hosted git repository.

remm 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 be5025d  64485: Fix possible resource leak
be5025d is described below

commit be5025de4d21cb5e0e7e4573e22c6b8a79e01443
Author: remm <remm@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 eb3c72d..056cf3b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -87,6 +87,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="Jasper">


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


Mime
View raw message