Author: markt Date: Wed Aug 24 14:02:16 2016 New Revision: 1757527 URL: http://svn.apache.org/viewvc?rev=1757527&view=rev Log: Fix a file descriptor leak when reading the global web.xml.
Added: tomcat/trunk/java/org/apache/tomcat/util/descriptor/InputSourceUtil.java (with props) Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXmlParser.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1757527&r1=1757526&r2=1757527&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Wed Aug 24 14:02:16 2016 @@ -80,6 +80,7 @@ import org.apache.tomcat.util.bcel.class import org.apache.tomcat.util.bcel.classfile.ElementValuePair; import org.apache.tomcat.util.bcel.classfile.JavaClass; import org.apache.tomcat.util.buf.UriUtil; +import org.apache.tomcat.util.descriptor.InputSourceUtil; import org.apache.tomcat.util.descriptor.XmlErrorHandler; import org.apache.tomcat.util.descriptor.web.ContextEjb; import org.apache.tomcat.util.descriptor.web.ContextEnvironment; @@ -1504,6 +1505,8 @@ public class ContextConfig implements Li if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp && entry.getHostTimeStamp() == hostTimeStamp) { + InputSourceUtil.close(globalWebXml); + InputSourceUtil.close(hostWebXml); return entry.getWebXml(); } Added: tomcat/trunk/java/org/apache/tomcat/util/descriptor/InputSourceUtil.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/InputSourceUtil.java?rev=1757527&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/InputSourceUtil.java (added) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/InputSourceUtil.java Wed Aug 24 14:02:16 2016 @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.util.descriptor; + +import java.io.InputStream; + +import org.apache.tomcat.util.ExceptionUtils; +import org.xml.sax.InputSource; + +public final class InputSourceUtil { + + private InputSourceUtil() { + // Utility class. Hide default constructor. + } + + + public static void close(InputSource inputSource) { + if (inputSource == null) { + // Nothing to do + return; + } + + InputStream is = inputSource.getByteStream(); + if (is != null) { + try { + is.close(); + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + } + } + + } +} Propchange: tomcat/trunk/java/org/apache/tomcat/util/descriptor/InputSourceUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXmlParser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXmlParser.java?rev=1757527&r1=1757526&r2=1757527&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXmlParser.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXmlParser.java Wed Aug 24 14:02:16 2016 @@ -17,13 +17,12 @@ package org.apache.tomcat.util.descriptor.web; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; -import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.descriptor.DigesterFactory; +import org.apache.tomcat.util.descriptor.InputSourceUtil; import org.apache.tomcat.util.descriptor.XmlErrorHandler; import org.apache.tomcat.util.digester.Digester; import org.apache.tomcat.util.res.StringManager; @@ -136,15 +135,7 @@ public class WebXmlParser { source.getSystemId()), e); ok = false; } finally { - InputStream is = source.getByteStream(); - if (is != null) { - try { - is.close(); - } catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - } - } - + InputSourceUtil.close(source); digester.reset(); ruleSet.recycle(); } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1757527&r1=1757526&r2=1757527&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed Aug 24 14:02:16 2016 @@ -171,6 +171,9 @@ <bug>60022</bug>: Improve handling when a WAR file and/or the associated exploded directory are symlinked into the <code>appBase</code>. (markt) </fix> + <fix> + Fix a file descriptor leak when reading the global web.xml. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org