Skip to content

Commit ef42f3c

Browse files
[JENKINS-75879] GStringTemplateEngine causes memory leak in class loading (#10938)
1 parent c64d70f commit ef42f3c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/src/main/java/hudson/PluginManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
218218
*/
219219
/* private final */ static int CHECK_UPDATE_ATTEMPTS;
220220

221+
/**
222+
* Class name prefixes to skip in the class loading
223+
*/
224+
private static final String[] CLASS_PREFIXES_TO_SKIP = {
225+
"SimpleTemplateScript", // cf. groovy.text.SimpleTemplateEngine
226+
"groovy.tmp.templates.GStringTemplateScript", // Leaks on classLoader in some cases, see JENKINS-75879
227+
};
228+
221229
static {
222230
try {
223231
// Secure initialization
@@ -2409,8 +2417,10 @@ public UberClassLoader(List<PluginWrapper> activePlugins) {
24092417

24102418
@Override
24112419
protected Class<?> findClass(String name) throws ClassNotFoundException {
2412-
if (name.startsWith("SimpleTemplateScript")) { // cf. groovy.text.SimpleTemplateEngine
2413-
throw new ClassNotFoundException("ignoring " + name);
2420+
for (String namePrefixToSkip : CLASS_PREFIXES_TO_SKIP) {
2421+
if (name.startsWith(namePrefixToSkip)) {
2422+
throw new ClassNotFoundException("ignoring " + name);
2423+
}
24142424
}
24152425
return loaded.computeIfAbsent(name, this::computeValue).orElseThrow(() -> new ClassNotFoundException(name));
24162426
}

0 commit comments

Comments
 (0)