You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/02/20 07:47:58 UTC

svn commit: r1783718 - /felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java

Author: cziegeler
Date: Mon Feb 20 07:47:57 2017
New Revision: 1783718

URL: http://svn.apache.org/viewvc?rev=1783718&view=rev
Log:
FELIX-5540 : DataModelHelperImpl leaks Zip Streams / native Memory. Apply patch from Fabian Lange

Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java?rev=1783718&r1=1783717&r2=1783718&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java Mon Feb 20 07:47:57 2017
@@ -108,10 +108,22 @@ public class DataModelHelperImpl impleme
                     }
                     entry = zin.getNextEntry();
                 }
+                // as the ZipInputStream is not used further it would not be closed.
+                if (is == null)
+                {
+                    try
+                    {
+                        zin.close();
+                    }
+                    catch (IOException ex)
+                    {
+                        // Not much we can do.
+                    }
+                }
             }
             else if (url.getPath().endsWith(".gz"))
             {
-                is = new GZIPInputStream(FileUtil.openURL(url));                    
+                is = new GZIPInputStream(FileUtil.openURL(url));
             }
             else
             {
@@ -454,18 +466,17 @@ public class DataModelHelperImpl impleme
             }
             private byte[] loadEntry(String name) throws IOException
             {
-                InputStream is = FileUtil.openURL(bundleUrl);
+                ZipInputStream zis = new ZipInputStream(FileUtil.openURL(bundleUrl));
                 try
                 {
-                    ZipInputStream jis = new ZipInputStream(is);
-                    for (ZipEntry e = jis.getNextEntry(); e != null; e = jis.getNextEntry())
+                    for (ZipEntry e = zis.getNextEntry(); e != null; e = zis.getNextEntry())
                     {
                         if (name.equalsIgnoreCase(e.getName()))
                         {
                             ByteArrayOutputStream baos = new ByteArrayOutputStream();
                             byte[] buf = new byte[1024];
                             int n;
-                            while ((n = jis.read(buf, 0, buf.length)) > 0)
+                            while ((n = zis.read(buf, 0, buf.length)) > 0)
                             {
                                 baos.write(buf, 0, n);
                             }
@@ -475,7 +486,7 @@ public class DataModelHelperImpl impleme
                 }
                 finally
                 {
-                    is.close();
+                    zis.close();
                 }
                 return null;
             }