Author: kkolinko Date: Sat Jan 5 01:43:28 2013 New Revision: 1429186 URL: http://svn.apache.org/viewvc?rev=1429186&view=rev Log: Merged revisions r1429173 r1429182 from tomcat/trunk: Fix leak of servlet instances when running with SecurityManager: a) In case when initServlet() or destroy() fail. b) In case of a SingleThreadModel servlet. (fix wrong argument)
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1429173,1429182 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=1429186&r1=1429185&r2=1429186&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java Sat Jan 5 01:43:28 2013 @@ -1256,13 +1256,20 @@ public class StandardWrapper extends Con servlet); if( Globals.IS_SECURITY_ENABLED) { - - Object[] args = new Object[]{(facade)}; - SecurityUtil.doAsPrivilege("init", - servlet, - classType, - args); - args = null; + boolean success = false; + try { + Object[] args = new Object[] { facade }; + SecurityUtil.doAsPrivilege("init", + servlet, + classType, + args); + success = true; + } finally { + if (!success) { + // destroy() will not be called, thus clear the reference now + SecurityUtil.remove(servlet); + } + } } else { servlet.init(facade); } @@ -1458,9 +1465,12 @@ public class StandardWrapper extends Con (InstanceEvent.BEFORE_DESTROY_EVENT, instance); if( Globals.IS_SECURITY_ENABLED) { - SecurityUtil.doAsPrivilege("destroy", - instance); - SecurityUtil.remove(instance); + try { + SecurityUtil.doAsPrivilege("destroy", + instance); + } finally { + SecurityUtil.remove(instance); + } } else { instance.destroy(); } @@ -1513,8 +1523,11 @@ public class StandardWrapper extends Con while (!instancePool.isEmpty()) { Servlet s = instancePool.pop(); if (Globals.IS_SECURITY_ENABLED) { - SecurityUtil.doAsPrivilege("destroy", s); - SecurityUtil.remove(instance); + try { + SecurityUtil.doAsPrivilege("destroy", s); + } finally { + SecurityUtil.remove(s); + } } else { s.destroy(); } Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1429186&r1=1429185&r2=1429186&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Jan 5 01:43:28 2013 @@ -78,6 +78,11 @@ Make HTTP Digest authentication header parsing tolerant of invalid headers sent by known buggy clients. (markt) </add> + <fix> + Fix memory leak of servlet instances when running with a + SecurityManager and either init() or destroy() methods fail + or the servlet is a SingleThreadModel one. (kkolinko) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org