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

markt-asf 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 392ec5a542 Restore fd leak protection
392ec5a542 is described below

commit 392ec5a5421eae7f0a1d63557533ce87fe1341b1
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Jun 30 18:30:04 2026 +0100

    Restore fd leak protection
---
 .../org/apache/catalina/startup/ContextConfig.java | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/startup/ContextConfig.java 
b/java/org/apache/catalina/startup/ContextConfig.java
index 5235a692fe..3fea99cb66 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -1704,24 +1704,44 @@ public class ContextConfig implements LifecycleListener 
{
         long hostTimeStamp = 0;
 
         if (globalWebXml != null) {
+            URLConnection uc = null;
             try {
                 URI uri = new URI(globalWebXml.getSystemId());
                 URL url = uri.toURL();
-                URLConnection uc = url.openConnection();
+                uc = url.openConnection();
                 globalTimeStamp = uc.getLastModified();
             } catch (IOException | URISyntaxException | 
IllegalArgumentException e) {
                 globalTimeStamp = -1;
+            } finally {
+                if (uc != null) {
+                    try {
+                        uc.getInputStream().close();
+                    } catch (IOException ioe) {
+                        ExceptionUtils.handleThrowable(ioe);
+                        globalTimeStamp = -1;
+                    }
+                }
             }
         }
 
         if (hostWebXml != null) {
+            URLConnection uc = null;
             try {
                 URI uri = new URI(hostWebXml.getSystemId());
                 URL url = uri.toURL();
-                URLConnection uc = url.openConnection();
+                uc = url.openConnection();
                 hostTimeStamp = uc.getLastModified();
             } catch (IOException | URISyntaxException | 
IllegalArgumentException e) {
                 hostTimeStamp = -1;
+            } finally {
+                if (uc != null) {
+                    try {
+                        uc.getInputStream().close();
+                    } catch (IOException ioe) {
+                        ExceptionUtils.handleThrowable(ioe);
+                        hostTimeStamp = -1;
+                    }
+                }
             }
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to