Bug 738421 - Close zip when done reading. r=sriram

This commit is contained in:
Wes Johnston 2012-03-22 15:11:39 -07:00
parent 0a128bef50
commit 63a240359f
2 changed files with 21 additions and 7 deletions

View File

@ -297,14 +297,19 @@ public class Favicons {
} catch (Exception e) {
// Trying to read icons from nested jar files will fail
if (mFaviconUrl.startsWith("jar:jar:")) {
InputStream stream = GeckoJarReader.getStream(mFaviconUrl);
if (stream != null) {
image = new BitmapDrawable(stream);
} else {
Log.d(LOGTAG, "Error getting favicon from jar: " + e);
try {
InputStream stream = GeckoJarReader.getStream(mFaviconUrl);
if (stream != null) {
image = new BitmapDrawable(stream);
stream.close();
} else {
Log.d(LOGTAG, "Error getting favicon from jar: " + e);
}
} catch(IOException ex) {
Log.e(LOGTAG, "Error closing stream", ex);
}
} else {
Log.d(LOGTAG, "Error downloading favicon: " + e);
Log.e(LOGTAG, "Error downloading favicon", e);
}
} finally {
if (urlConnection != null && urlConnection instanceof HttpURLConnection) {

View File

@ -26,11 +26,12 @@ public class GeckoJarReader {
Stack<String> jarUrls = parseUrl(url);
ZipInputStream inputStream = null;
ZipFile zip = null;
try {
// Load the initial jar file as a zip
URL fileUrl = new URL(jarUrls.pop());
File file = new File(fileUrl.getPath());
ZipFile zip = new ZipFile(file);
zip = new ZipFile(file);
ZipEntry entry = null;
// loop through children jar files until we reach the innermost one
@ -63,6 +64,14 @@ public class GeckoJarReader {
Log.e(LOGTAG, "Exception ", ex);
} catch (Exception ex) {
Log.e(LOGTAG, "Exception ", ex);
} finally {
if (zip != null) {
try {
zip.close();
} catch(IOException ex) {
Log.e(LOGTAG, "Error closing zip", ex);
}
}
}
return inputStream;