diff --git a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java index 4c3fd2b..5e07d76 100644 --- a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java +++ b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java @@ -101,15 +101,14 @@ public class BookmarkManager { final File bookmarksFile = new File(mFilesDir, FILE_BOOKMARKS); BufferedReader bookmarksReader = null; + InputStream inputStream = null; try { - final InputStream inputStream; if (bookmarksFile.exists() && bookmarksFile.isFile()) { inputStream = new FileInputStream(bookmarksFile); } else { inputStream = mContext.getResources().openRawResource(R.raw.default_bookmarks); } - bookmarksReader = - new BufferedReader(new InputStreamReader(inputStream)); + bookmarksReader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = bookmarksReader.readLine()) != null) { try { @@ -130,6 +129,7 @@ public class BookmarkManager { Log.e(TAG, "Error reading the bookmarks file", e); } finally { Utils.close(bookmarksReader); + Utils.close(inputStream); } mBookmarksMap = bookmarks; mReady = true; diff --git a/app/src/main/java/acr/browser/lightning/utils/AdBlock.java b/app/src/main/java/acr/browser/lightning/utils/AdBlock.java index 0f06386..706596f 100644 --- a/app/src/main/java/acr/browser/lightning/utils/AdBlock.java +++ b/app/src/main/java/acr/browser/lightning/utils/AdBlock.java @@ -57,8 +57,9 @@ public class AdBlock { @Override public void run() { AssetManager asset = context.getAssets(); + BufferedReader reader = null; try { - BufferedReader reader = new BufferedReader(new InputStreamReader( + reader = new BufferedReader(new InputStreamReader( asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME))); String line; while ((line = reader.readLine()) != null) { @@ -67,6 +68,8 @@ public class AdBlock { } catch (IOException e) { Log.wtf(TAG, "Reading blocked domains list from file '" + BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e); + } finally { + Utils.close(reader); } } });