changeset 682:d5d3f8a62906

Ensure JarFile handles do not leak.
author Adam Domurad <adomurad@redhat.com>
date Tue, 23 Apr 2013 12:30:34 -0400
parents 1bdcb1e255b5
children db364934ee33
files ChangeLog netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Apr 23 12:29:13 2013 -0400
+++ b/ChangeLog	Tue Apr 23 12:30:34 2013 -0400
@@ -1,3 +1,9 @@
+2013-04-23  Adam Domurad  <adomurad@redhat.com>
+
+	Ensure JarFile handles do not leak.
+	* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java:
+	Ensure close is called for each JarFile.
+
 2013-04-23  Adam Domurad  <adomurad@redhat.com>
 
 	* tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java:
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Tue Apr 23 12:29:13 2013 -0400
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Tue Apr 23 12:30:34 2013 -0400
@@ -862,6 +862,8 @@
                         break;
                     }
                 }
+
+                jarFile.close();
             } catch (IOException e) {
                 /*
                  * After this exception is caught, it is escaped. This will skip
@@ -884,12 +886,15 @@
         File f = tracker.getCacheFile(location);
 
         if( f != null) {
+            JarFile mainJar = null;
             try {
-                JarFile mainJar = new JarFile(f);
+                mainJar = new JarFile(f);
                 mainClass = mainJar.getManifest().
                         getMainAttributes().getValue("Main-Class");
             } catch (IOException ioe) {
                 mainClass = null;
+            } finally {
+                StreamUtils.closeSilently(mainJar);
             }
         }
 
@@ -1305,6 +1310,7 @@
                                 jarEntries.add(je.getName());
                             }
 
+                            jarFile.close();
                         }
 
                         addURL(jar.getLocation());
@@ -1328,6 +1334,8 @@
                             JarIndex index = JarIndex.getJarIndex(jarFile, null);
                             if (index != null)
                                 jarIndexes.add(index);
+
+                            jarFile.close();
                         } else {
                             CachedJarFileCallback.getInstance().addMapping(jar.getLocation(), jar.getLocation());
                         }
@@ -1401,6 +1409,7 @@
                                      new FileOutputStream(outFile));
 
             }
+            jarFile.close();
         } catch (IOException ex) {
             if (JNLPRuntime.isDebug())
                 ex.printStackTrace();