Author: markt Date: Sun Mar 23 09:36:32 2014 New Revision: 1580479 URL: http://svn.apache.org/r1580479 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56275 Fix memory leak if a Filter throws an exception during its destroy() method
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1580479&r1=1580478&r2=1580479&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Sun Mar 23 09:36:32 2014 @@ -64,12 +64,6 @@ PATCHES PROPOSED TO BACKPORT: Thus I am OK with this change. -1: -* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56275 - Fix memory leak if a Filter throws an exception during its destroy() method - http://people.apache.org/~markt/patches/2014-03-19-bug56275-tc6-v1.patch - +1: markt, schultz, kkolinko, remm - -1: - * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54475 Add Java 8 support to SMAP generation for JSPs. Patch by Robbie Gibson. Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java?rev=1580479&r1=1580478&r2=1580479&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java Sun Mar 23 09:36:32 2014 @@ -44,6 +44,7 @@ import org.apache.catalina.security.Secu import org.apache.catalina.util.Enumerator; import org.apache.catalina.util.StringManager; import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.log.SystemLogHandler; import org.apache.tomcat.util.modeler.Registry; @@ -112,8 +113,10 @@ public final class ApplicationFilterConf } this.context = context; - setFilterDef(filterDef); + this.filterDef = filterDef; + // Allocate a new filter instance + getFilter(); } @@ -346,16 +349,22 @@ public final class ApplicationFilterConf if (this.filter != null) { - if (Globals.IS_SECURITY_ENABLED) { - try { - SecurityUtil.doAsPrivilege("destroy", filter); - } catch(java.lang.Exception ex){ - context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex); - } finally { - SecurityUtil.remove(filter); + try { + if (Globals.IS_SECURITY_ENABLED) { + try { + SecurityUtil.doAsPrivilege("destroy", filter); + } finally { + SecurityUtil.remove(filter); + } + } else { + filter.destroy(); } - } else { - filter.destroy(); + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + context.getLogger().error(sm.getString( + "applicationFilterConfig.release", + filterDef.getFilterName(), + filterDef.getFilterClass()), t); } if (!context.getIgnoreAnnotations()) { try { @@ -370,64 +379,6 @@ public final class ApplicationFilterConf } - /** - * Set the filter definition we are configured for. This has the side - * effect of instantiating an instance of the corresponding filter class. - * - * @param filterDef The new filter definition - * - * @exception ClassCastException if the specified class does not implement - * the <code>javax.servlet.Filter</code> interface - * @exception ClassNotFoundException if the filter class cannot be found - * @exception IllegalAccessException if the filter class cannot be - * publicly instantiated - * @exception InstantiationException if an exception occurs while - * instantiating the filter object - * @exception ServletException if thrown by the filter's init() method - * @throws NamingException - * @throws InvocationTargetException - */ - void setFilterDef(FilterDef filterDef) - throws ClassCastException, ClassNotFoundException, - IllegalAccessException, InstantiationException, - ServletException, InvocationTargetException, NamingException { - - this.filterDef = filterDef; - if (filterDef == null) { - - // Release any previously allocated filter instance - if (this.filter != null){ - if (Globals.IS_SECURITY_ENABLED) { - try{ - SecurityUtil.doAsPrivilege("destroy", filter); - } catch(java.lang.Exception ex){ - context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex); - } finally { - SecurityUtil.remove(filter); - } - } else { - filter.destroy(); - } - if (!context.getIgnoreAnnotations()) { - try { - ((StandardContext)context).getAnnotationProcessor().preDestroy(this.filter); - } catch (Exception e) { - context.getLogger().error("ApplicationFilterConfig.preDestroy", e); - } - } - } - this.filter = null; - - } else { - - // Allocate a new filter instance - Filter filter = getFilter(); - - } - - } - - // -------------------------------------------------------- Private Methods Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1580479&r1=1580478&r2=1580479&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties Sun Mar 23 09:36:32 2014 @@ -31,6 +31,7 @@ applicationDispatcher.specViolation.resp applicationFilterConfig.jmxRegisterFail=JMX registration failed for filter of type [{0}] and name [{1}] applicationFilterConfig.jmxUnregister=JMX de-registration complete for filter of type [{0}] and name [{1}] applicationFilterConfig.jmxUnregisterFail=JMX de-registration failed for filter of type [{0}] and name [{1}] +applicationFilterConfig.release=Failed to destroy the filter named [{0}] of type [{1}] applicationRequest.badParent=Cannot locate parent Request implementation applicationRequest.badRequest=Request is not a javax.servlet.ServletRequestWrapper applicationResponse.badParent=Cannot locate parent Response implementation Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1580479&r1=1580478&r2=1580479&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Sun Mar 23 09:36:32 2014 @@ -66,6 +66,11 @@ <scode> Use StringBuilder in DefaultServlet. (kkolinko) </scode> + <fix> + <bug>56275</bug>: Allow web applications to be stopped cleanly even if + filters throw exceptions when their destroy() method is called. + (markt/kkolinko) + </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