You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by mr...@apache.org on 2004/06/07 04:27:52 UTC

cvs commit: xml-commons/java/external/src/javax/xml/transform FactoryFinder.java

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 &&