Return-Path: Delivered-To: apmail-xml-commons-cvs-archive@www.apache.org Received: (qmail 89692 invoked from network); 7 Jun 2004 02:27:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Jun 2004 02:27:54 -0000 Received: (qmail 58277 invoked by uid 500); 7 Jun 2004 02:27:53 -0000 Delivered-To: apmail-xml-commons-cvs-archive@xml.apache.org Received: (qmail 58254 invoked by uid 500); 7 Jun 2004 02:27:53 -0000 Mailing-List: contact commons-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list commons-cvs@xml.apache.org Received: (qmail 58241 invoked by uid 99); 7 Jun 2004 02:27:53 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Sun, 06 Jun 2004 19:27:53 -0700 Received: (qmail 89686 invoked by uid 1678); 7 Jun 2004 02:27:52 -0000 Date: 7 Jun 2004 02:27:52 -0000 Message-ID: <20040607022752.89685.qmail@minotaur.apache.org> From: mrglavas@apache.org To: xml-commons-cvs@apache.org Subject: cvs commit: xml-commons/java/external/src/javax/xml/transform FactoryFinder.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N mrglavas 2004/06/06 19:27:52 Modified: java/external/src/javax/xml/parsers Tag: tck-jaxp-1_2_0 FactoryFinder.java java/external/src/javax/xml/transform Tag: tck-jaxp-1_2_0 FactoryFinder.java Log: Fixing a couple potential memory leaks. The input stream used for loading properties may never be closed if an IOException is thrown while reading from it. Adding finally blocks so that the input stream will always be closed. The reader used to read the service provider is never closed if an IOException is thrown while reading from it. Adding a finally block so that the reader will always be closed. Revision Changes Path No revision No revision 1.7.6.8 +20 -3 xml-commons/java/external/src/javax/xml/parsers/FactoryFinder.java Index: FactoryFinder.java =================================================================== RCS file: /home/cvs/xml-commons/java/external/src/javax/xml/parsers/FactoryFinder.java,v retrieving revision 1.7.6.7 retrieving revision 1.7.6.8 diff -u -r1.7.6.7 -r1.7.6.8 --- FactoryFinder.java 1 May 2004 23:07:43 -0000 1.7.6.7 +++ FactoryFinder.java 7 Jun 2004 02:27:52 -0000 1.7.6.8 @@ -138,6 +138,7 @@ synchronized (FactoryFinder.class) { boolean runBlock = false; + FileInputStream fis = null; try { if (lastModified >= 0) { @@ -166,9 +167,8 @@ // Try to read from $java.home/lib/jaxp.properties jaxpProperties = new Properties(); - FileInputStream fis = ss.getFileInputStream(f); + fis = ss.getFileInputStream(f); jaxpProperties.load(fis); - fis.close(); } } catch (Exception x) { @@ -178,6 +178,16 @@ // || x instanceof SecurityException) // In both cases, ignore and continue w/ next location } + finally { + // try to close the input stream if one was opened. + if (fis != null) { + try { + fis.close(); + } + // Ignore the exception. + catch (IOException exc) {} + } + } } if (jaxpProperties != null) { @@ -336,10 +346,17 @@ // XXX Does not handle all possible input as specified by the // Jar Service Provider specification factoryClassName = rd.readLine(); - rd.close(); } catch (IOException x) { // No provider found return null; + } + finally { + try { + // try to close the reader. + rd.close(); + } + // Ignore the exception. + catch (IOException exc) {} } if (factoryClassName != null && No revision No revision 1.7.6.8 +20 -3 xml-commons/java/external/src/javax/xml/transform/FactoryFinder.java Index: FactoryFinder.java =================================================================== RCS file: /home/cvs/xml-commons/java/external/src/javax/xml/transform/FactoryFinder.java,v retrieving revision 1.7.6.7 retrieving revision 1.7.6.8 diff -u -r1.7.6.7 -r1.7.6.8 --- FactoryFinder.java 1 May 2004 23:07:44 -0000 1.7.6.7 +++ FactoryFinder.java 7 Jun 2004 02:27:52 -0000 1.7.6.8 @@ -138,6 +138,7 @@ synchronized (FactoryFinder.class) { boolean runBlock = false; + FileInputStream fis = null; try { if (lastModified >= 0) { @@ -166,9 +167,8 @@ // Try to read from $java.home/lib/jaxp.properties jaxpProperties = new Properties(); - FileInputStream fis = ss.getFileInputStream(f); + fis = ss.getFileInputStream(f); jaxpProperties.load(fis); - fis.close(); } } catch (Exception x) { @@ -178,6 +178,16 @@ // || x instanceof SecurityException) // In both cases, ignore and continue w/ next location } + finally { + // try to close the input stream if one was opened. + if (fis != null) { + try { + fis.close(); + } + // Ignore the exception. + catch (IOException exc) {} + } + } } if (jaxpProperties != null) { @@ -336,10 +346,17 @@ // XXX Does not handle all possible input as specified by the // Jar Service Provider specification factoryClassName = rd.readLine(); - rd.close(); } catch (IOException x) { // No provider found return null; + } + finally { + try { + // try to close the reader. + rd.close(); + } + // Ignore the exception. + catch (IOException exc) {} } if (factoryClassName != null &&