]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Fix some resource leaks.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Fri, 12 Feb 2016 23:28:54 +0000 (00:28 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Fri, 12 Feb 2016 23:28:54 +0000 (00:28 +0100)
src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java

index 80bac89a7688b3fbbd0cf8e1509546807f2532d3..61fd524ef6ada1c729a087779a4911545f571406 100644 (file)
@@ -314,10 +314,10 @@ public class DictionaryApplication extends Application {
                 DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.put(
                         dictionaryInfo.uncompressedFilename, dictionaryInfo);
             }
-            reader.close();
         } catch (IOException e) {
             Log.e(LOG, "Failed to load downloadable dictionary lists.", e);
         }
+        try { reader.close(); } catch (IOException e) {}
     }
 
     private File dictDir;
index e05da14f443c6c5d38907cb6d4f9cd77c253891e..673c256a051cc6c2335a6b04f64450f4d259d800 100644 (file)
@@ -164,20 +164,21 @@ public class DictionaryManagerActivity extends ActionBarActivity {
                 
                 
                 final File localZipFile = new File(Uri.parse(dest).getPath());
+                ZipFile zipFile = null;
+                InputStream zipIn = null;
+                OutputStream zipOut = null;
                 try {
-                    ZipFile zipFile = new ZipFile(localZipFile);
+                    zipFile = new ZipFile(localZipFile);
                     final ZipEntry zipEntry = zipFile.entries().nextElement();
                     Log.d(LOG, "Unzipping entry: " + zipEntry.getName());
-                    final InputStream zipIn = zipFile.getInputStream(zipEntry);
+                    zipIn = zipFile.getInputStream(zipEntry);
                     File targetFile = new File(application.getDictDir(), zipEntry.getName());
                     if (targetFile.exists()) {
                         targetFile.renameTo(new File(targetFile.getAbsolutePath().replace(".quickdic", ".bak.quickdic")));
                         targetFile = new File(application.getDictDir(), zipEntry.getName());
                     }
-                    final OutputStream zipOut = new FileOutputStream(targetFile);
+                    zipOut = new FileOutputStream(targetFile);
                     copyStream(zipIn, zipOut);
-                    zipFile.close();
-                    zipOut.close();
                     application.backgroundUpdateDictionaries(dictionaryUpdater);
                     Toast.makeText(context, getString(R.string.installationFinished, dest),
                             Toast.LENGTH_LONG).show();
@@ -190,6 +191,9 @@ public class DictionaryManagerActivity extends ActionBarActivity {
                     new AlertDialog.Builder(context).setTitle(getString(R.string.error)).setMessage(msg).setNeutralButton("Close", null).show();
                     Log.e(LOG, "Failed to unzip.", e);
                 } finally {
+                    try { if (zipOut != null) zipOut.close(); } catch (IOException e) {}
+                    try { if (zipIn != null) zipIn.close(); } catch (IOException e) {}
+                    try { if (zipFile != null) zipFile.close(); } catch (IOException e) {}
                     localZipFile.delete();
                 }
             }