From 39a9b8fe3c00c5d03d1905b6f7087bb5cbf4cacd Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 28 Jun 2011 19:25:18 -0700 Subject: [PATCH] [FIXED JENKINS-8042] Fixed a file handle leak --- changelog.html | 3 +++ core/src/main/java/hudson/XmlFile.java | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/changelog.html b/changelog.html index 2d154a9620..82b2981587 100644 --- a/changelog.html +++ b/changelog.html @@ -58,6 +58,9 @@ Upcoming changes
  • Restart button does not restart jenkins after plugin upload (issue 10044) +
  • + Fixed a file handle leak in GET config.xml API call + (issue 8042)
  • Groovy script console is now syntax highlighted.
  • diff --git a/core/src/main/java/hudson/XmlFile.java b/core/src/main/java/hudson/XmlFile.java index f5b836ce36..a896890829 100644 --- a/core/src/main/java/hudson/XmlFile.java +++ b/core/src/main/java/hudson/XmlFile.java @@ -31,8 +31,10 @@ import com.thoughtworks.xstream.io.xml.XppReader; import hudson.model.Descriptor; import hudson.util.AtomicFileWriter; import hudson.util.IOException2; +import hudson.util.IOUtils; import hudson.util.XStream2; import org.xml.sax.Attributes; +import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.ext.Locator2; @@ -234,8 +236,11 @@ public final class XmlFile { this.encoding = encoding; } } + InputSource input = new InputSource(file.toURI().toASCIIString()); + input.setByteStream(new FileInputStream(file)); + try { - JAXP.newSAXParser().parse(file,new DefaultHandler() { + JAXP.newSAXParser().parse(input,new DefaultHandler() { private Locator loc; @Override public void setDocumentLocator(Locator locator) { @@ -275,6 +280,9 @@ public final class XmlFile { throw new IOException2("Failed to detect encoding of "+file,e); } catch (ParserConfigurationException e) { throw new AssertionError(e); // impossible + } finally { + // some JAXP implementations appear to leak the file handle if we just call parse(File,DefaultHandler) + input.getByteStream().close(); } } -- GitLab