Skip to content
Permalink
Browse files

[FIXED JENKINS-39159] If we create a URLClassLoader we should also cl…

…ose it.
  • Loading branch information...
jglick committed Feb 6, 2017
1 parent 252e639 commit 4e3565175ff3d313573d19e0aa98382866233fd3
@@ -145,6 +145,7 @@ public Object evaluate(ClassLoader loader, Binding binding) throws Exception {
if (!calledConfiguring) {
throw new IllegalStateException("you need to call configuring or a related method before using GroovyScript");
}
URLClassLoader urlcl = null;
List<ClasspathEntry> cp = getClasspath();
if (!cp.isEmpty()) {
List<URL> urlList = new ArrayList<URL>(cp.size());
@@ -154,18 +155,24 @@ public Object evaluate(ClassLoader loader, Binding binding) throws Exception {
urlList.add(entry.getURL());
}

loader = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), loader);
loader = urlcl = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), loader);
}
loader = GroovySandbox.createSecureClassLoader(loader);
if (sandbox) {
GroovyShell shell = new GroovyShell(loader, binding, GroovySandbox.createSecureCompilerConfiguration());
try {
return GroovySandbox.run(shell.parse(script), Whitelist.all());
} catch (RejectedAccessException x) {
throw ScriptApproval.get().accessRejected(x, ApprovalContext.create());
try {
loader = GroovySandbox.createSecureClassLoader(loader);
if (sandbox) {
GroovyShell shell = new GroovyShell(loader, binding, GroovySandbox.createSecureCompilerConfiguration());
try {
return GroovySandbox.run(shell.parse(script), Whitelist.all());
} catch (RejectedAccessException x) {
throw ScriptApproval.get().accessRejected(x, ApprovalContext.create());
}
} else {
return new GroovyShell(loader, binding).evaluate(ScriptApproval.get().using(script, GroovyLanguage.get()));
}
} finally {
if (urlcl != null) {
urlcl.close();
}
} else {
return new GroovyShell(loader, binding).evaluate(ScriptApproval.get().using(script, GroovyLanguage.get()));
}
}

0 comments on commit 4e35651

Please sign in to comment.
You can’t perform that action at this time.