Skip to content
This repository was archived by the owner on Aug 17, 2018. It is now read-only.

Commit 2a4ac4b

Browse files
author
Kin Man Chung
committed
- Fix a potential memory leak: JspServlet holds an instance of
JspRuntimeContext, which in term, holds an instance of the WebAppClassLoader. Since JspServlet is loaded with the first JSP application, and has the life time of the web container, this WebAppClassLoader is kept alive, even after the application is undeployed. svn path=/trunk/; revision=1275
1 parent 7378736 commit 2a4ac4b

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

impl/src/main/java/org/apache/jasper/JspCompilationContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class JspCompilationContext {
111111
private String baseURI;
112112
private String outputDir;
113113
private ServletContext context;
114-
private URLClassLoader loader;
114+
private ClassLoader loader;
115115

116116
private JspRuntimeContext rctxt;
117117

@@ -243,9 +243,9 @@ public void setClassPath(String classPath) {
243243
* this JSP?
244244
*/
245245
public ClassLoader getClassLoader() {
246-
if( loader != null )
247-
return loader;
248-
return rctxt.getParentClassLoader();
246+
if( loader == null )
247+
loader = rctxt.getParentClassLoader();
248+
return loader;
249249
}
250250

251251
public void setClassLoader(URLClassLoader loader) {

impl/src/main/java/org/apache/jasper/compiler/JspRuntimeContext.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,8 @@ public JspRuntimeContext(ServletContext context, Options options) {
171171
bytecodeBirthTimes = new ConcurrentHashMap<String, Long>(hashSize);
172172
packageMap = new ConcurrentHashMap<String, Map<String, JavaFileObject>>();
173173

174-
// Get the parent class loader
175-
parentClassLoader = Thread.currentThread().getContextClassLoader();
176-
if (parentClassLoader == null) {
177-
parentClassLoader = this.getClass().getClassLoader();
178-
}
179-
180174
if (log.isLoggable(Level.FINEST)) {
175+
ClassLoader parentClassLoader = getParentClassLoader();
181176
if (parentClassLoader != null) {
182177
log.finest(Localizer.getMessage("jsp.message.parent_class_loader_is",
183178
parentClassLoader.toString()));
@@ -221,7 +216,6 @@ public JspRuntimeContext(ServletContext context, Options options) {
221216
*/
222217
private ServletContext context;
223218
private Options options;
224-
private ClassLoader parentClassLoader;
225219
private PermissionCollection permissionCollection;
226220
private CodeSource codeSource;
227221
private String classpath;
@@ -318,6 +312,11 @@ public CodeSource getCodeSource() {
318312
* @return ClassLoader parent
319313
*/
320314
public ClassLoader getParentClassLoader() {
315+
ClassLoader parentClassLoader =
316+
Thread.currentThread().getContextClassLoader();
317+
if (parentClassLoader == null) {
318+
parentClassLoader = this.getClass().getClassLoader();
319+
}
321320
return parentClassLoader;
322321
}
323322

@@ -341,8 +340,6 @@ public void destroy() {
341340
for (JspServletWrapper jsw: jsps.values()) {
342341
jsw.destroy();
343342
}
344-
345-
parentClassLoader = null;
346343
}
347344

348345
/**
@@ -580,6 +577,7 @@ private void initSecurity() {
580577
permissionCollection.add( new RuntimePermission(
581578
"accessClassInPackage.org.apache.jasper.runtime") );
582579

580+
ClassLoader parentClassLoader = getParentClassLoader();
583581
if (parentClassLoader instanceof URLClassLoader) {
584582
URL [] urls = ((URLClassLoader)parentClassLoader).getURLs();
585583
String jarUrl = null;

0 commit comments

Comments
 (0)