提交 67347c3c 编写于 作者: O Oleg Nenashev 提交者: GitHub

[FIXED JENKINS-37561, CID-1205051] - Prevent resource leak in...

[FIXED JENKINS-37561, CID-1205051] - Prevent resource leak in AntClassLoader#findClassInComponents() (#2517)

It has been originally reported by Coverity in https://scan5.coverity.com/reports.htm#v36021/p10292/fileInstanceId=97573616&defectInstanceId=28155759&mergedDefectId=1205051. It happens on Exceptional paths only, but actually I see 31 runaway handlers on my jenkins-2.18 instance (maybe happens due to plugin dynamic load failure)

The issue happens, because finally block is misplaced. It handles only the last stream in this cycle
上级 96c97860
......@@ -1352,31 +1352,25 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
throws ClassNotFoundException {
// we need to search the components of the path to see if
// we can find the class we want.
InputStream stream = null;
String classFilename = getClassFilename(name);
try {
Enumeration e = pathComponents.elements();
while (e.hasMoreElements()) {
File pathComponent = (File) e.nextElement();
try {
stream = getResourceStream(pathComponent, classFilename);
if (stream != null) {
log("Loaded from " + pathComponent + " "
+ classFilename, Project.MSG_DEBUG);
return getClassFromStream(stream, name, pathComponent);
}
} catch (SecurityException se) {
throw se;
} catch (IOException ioe) {
// ioe.printStackTrace();
log("Exception reading component " + pathComponent + " (reason: "
+ ioe.getMessage() + ")", Project.MSG_VERBOSE);
Enumeration e = pathComponents.elements();
while (e.hasMoreElements()) {
File pathComponent = (File) e.nextElement();
try (final InputStream stream = getResourceStream(pathComponent, classFilename)) {
if (stream != null) {
log("Loaded from " + pathComponent + " "
+ classFilename, Project.MSG_DEBUG);
return getClassFromStream(stream, name, pathComponent);
}
} catch (SecurityException se) {
throw se;
} catch (IOException ioe) {
// ioe.printStackTrace();
log("Exception reading component " + pathComponent + " (reason: "
+ ioe.getMessage() + ")", Project.MSG_VERBOSE);
}
throw new ClassNotFoundException(name);
} finally {
FileUtils.close(stream);
}
throw new ClassNotFoundException(name);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册