From 5359ac0ef534fd95fea23e2f20929f9e4375a94a Mon Sep 17 00:00:00 2001 From: Marc Miltenberger Date: Wed, 12 Jul 2017 20:16:00 +0200 Subject: [PATCH] Make sure to close the file after reading in. The parse(File) method does not close the file under all circumstances. --- .../brut/androlib/res/xml/ResXmlPatcher.java | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java index 4b5036a3..6e36379f 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java @@ -16,25 +16,31 @@ */ package brut.androlib.res.xml; -import brut.androlib.AndrolibException; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.xpath.*; -import java.io.File; -import java.io.IOException; +import brut.androlib.AndrolibException; /** * @author Connor Tumbleson @@ -249,7 +255,14 @@ public final class ResXmlPatcher { docFactory.setFeature(FEATURE_DISABLE_DOCTYPE_DECL, true); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); - return docBuilder.parse(file); + // Not using the parse(File) method on purpose, so that we can control when + // to close it. Somehow parse(File) does not seem to close the file in all cases. + FileInputStream inputStream = new FileInputStream(file); + try { + return docBuilder.parse(inputStream); + } finally { + inputStream.close(); + } } /**