Author: markt
Date: Sun Oct 25 13:31:48 2015
New Revision: 1710441

URL: http://svn.apache.org/viewvc?rev=1710441&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58486
Protect against two further possible memory leaks associated with XML
parsing

Modified:
    
tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java

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=1710441&r1=1710440&r2=1710441&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java 
(original)
+++ 
tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java 
Sun Oct 25 13:31:48 2015
@@ -27,6 +27,7 @@ import java.sql.DriverManager;
 import java.util.StringTokenizer;
 
 import javax.imageio.ImageIO;
+import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
@@ -38,6 +39,8 @@ import org.apache.juli.logging.LogFactor
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.compat.JreVendor;
 import org.apache.tomcat.util.res.StringManager;
+import org.w3c.dom.Document;
+import org.w3c.dom.ls.DOMImplementationLS;
 
 /**
  * Provide a workaround for known places where the Java Runtime environment can
@@ -423,15 +426,27 @@ public class JreMemoryLeakPreventionList
                 }
 
                 /*
-                 * Haven't got to the root of what is going on with this leak
-                 * but if a web app is the first to make the calls below the 
web
-                 * application class loader will be pinned in memory.
+                 * Various leaks related to the use of XML parsing.
                  */
                 if (xmlParsingProtection) {
-                    DocumentBuilderFactory factory =
-                        DocumentBuilderFactory.newInstance();
+                    /*
+                     * Haven't got to the root of what is going on with this
+                     * leak but if a web app is the first to make the following
+                     * two calls the web application class loader will be 
pinned
+                     * in memory.
+                     */
+                    DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
                     try {
-                        factory.newDocumentBuilder();
+                        DocumentBuilder documentBuilder = 
factory.newDocumentBuilder();
+                        // Bug 58486 identified two additional memory leaks.
+                        // The first is in DOMSerializerImpl.abort
+                        Document document = documentBuilder.newDocument();
+                        document.createElement("dummy");
+                        DOMImplementationLS implementation =
+                                
(DOMImplementationLS)document.getImplementation();
+                        
implementation.createLSSerializer().writeToString(document);
+                        // The second leak is in DOMNormalizer
+                        document.normalize();
                     } catch (ParserConfigurationException e) {
                         log.error(sm.getString("jreLeakListener.xmlParseFail"),
                                 e);



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

Reply via email to