bug 709330 - AboutHomeContent.getRecommendedAddonsStream() resource leak because ZipFile was not closed r=mfinkle
authorBrad Lassey <blassey@mozilla.com>
Fri, 16 Dec 2011 20:22:34 -0500
changeset 84736 43fd5d2ede79298b3d3cb8796e8ed6a77c76e9b6
parent 84735 93f523345fb614514d9a1e849470b1625e9526aa
child 84737 3f050eb4f8ac9a63faefd706959dbba8e26bfb24
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs709330
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 709330 - AboutHomeContent.getRecommendedAddonsStream() resource leak because ZipFile was not closed r=mfinkle
mobile/android/base/AboutHomeContent.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -231,23 +231,29 @@ public class AboutHomeContent extends Sc
         return null;
     }
 
     InputStream getRecommendedAddonsStream(Activity activity) throws Exception{
         InputStream is = getProfileRecommendedAddonsStream();
         if (is != null)
             return is;
         File applicationPackage = new File(activity.getApplication().getPackageResourcePath());
-        ZipFile zip = new ZipFile(applicationPackage);
-        if (zip == null)
-            return null;
-        ZipEntry fileEntry = zip.getEntry("recommended-addons.json");
-        if (fileEntry == null)
-            return null;
-        return zip.getInputStream(fileEntry);
+        ZipFile zip = null;
+        try {
+            zip = new ZipFile(applicationPackage);
+            if (zip == null)
+                return null;
+            ZipEntry fileEntry = zip.getEntry("recommended-addons.json");
+            if (fileEntry == null)
+                return null;
+            return zip.getInputStream(fileEntry);
+        } finally {
+            if (zip != null)
+                zip.close();
+        }
     }
 
     void readRecommendedAddons(final Activity activity) {
         GeckoAppShell.getHandler().post(new Runnable() {
             public void run() {
                 try {
                     byte[] buf = new byte[32768];
                     InputStream fileStream = getRecommendedAddonsStream(activity);