Author: markt Date: Mon Aug 23 20:35:03 2010 New Revision: 988296 URL: http://svn.apache.org/viewvc?rev=988296&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49669 Another Java class triggering a memory leak. This time javax.security.auth.Policy
Modified: tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java tomcat/trunk/webapps/docs/config/listeners.xml Modified: tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java?rev=988296&r1=988295&r2=988296&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Mon Aug 23 20:35:03 2010 @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.security.Policy; import javax.imageio.ImageIO; import javax.xml.parsers.DocumentBuilderFactory; @@ -93,6 +94,20 @@ public class JreMemoryLeakPreventionList this.keepAliveProtection = keepAliveProtection; } + /** + * Protect against the memory leak caused when the first call to + * <code>javax.security.auth.Policy</code> is triggered by a web + * application. This first call populate a static variable with a reference + * to the context class loader. Defaults to <code>true</code>. + */ + private boolean securityPolicyProtection = true; + public boolean iSsecurityPolicyProtection() { + return securityPolicyProtection; + } + public void setSecurityPolicyProtection(boolean securityPolicyProtection) { + this.securityPolicyProtection = securityPolicyProtection; + } + /** * Protect against the memory leak, when the initialization of the * Java Cryptography Architecture is triggered by initializing @@ -212,6 +227,19 @@ public class JreMemoryLeakPreventionList } /* + * Calling getPolicy retains a static reference to the context class + * loader. + */ + if (securityPolicyProtection) { + try { + Policy.getPolicy(); + } catch(SecurityException e) { + // Ignore. Don't need call to getPolicy() to be successful, + // just need to trigger static initializer. + } + } + + /* * Creating a MessageDigest during web application startup * initializes the Java Cryptography Architecture. Under certain * conditions this starts a Token poller thread with TCCL equal Modified: tomcat/trunk/webapps/docs/config/listeners.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=988296&r1=988295&r2=988296&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/listeners.xml (original) +++ tomcat/trunk/webapps/docs/config/listeners.xml Mon Aug 23 20:35:03 2010 @@ -270,6 +270,16 @@ service:jmx:rmi://<hostname>:10002 trigger a memory leak on reload. Defaults to <code>true</code>.</p> </attribute> + <attribute name="securityPolicyProtection" required="false"> + <p>Enables protection so that usage of + <code>javax.security.auth.Policy</code> by a web application does not + result in a memory leak. The first access of this class will trigger the + static initializer that will retain a static reference to the context + class loader. The protection calls the <code>getPolicy()</code> method + of this class to ensure that the static initializer is not triggered by + a web application. Defaults to <code>true</code>.</p> + </attribute> + <attribute name="tokenPollerProtection" required="false"> <p>Enables protection so that any token poller thread initialized by <code>sun.security.pkcs11.SunPKCS11.initToken()</code> does not --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org