Bug 1247557 - Close Cursors in AndroidImport. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 22 Feb 2016 14:55:43 -0800
changeset 333178 f0d1dd9ceaf28328026367aab39603a29bee7295
parent 332009 6008843fb7ba5de8a2c7e39bf6e2e4a2e7f1532b
child 514660 93c7ccdfca6e504e9e5875653ec6cc79cad3c3b7
push id11286
push usermichael.l.comella@gmail.com
push dateMon, 22 Feb 2016 22:55:51 +0000
reviewerssebastian
bugs1247557
milestone47.0a1
Bug 1247557 - Close Cursors in AndroidImport. r=sebastian MozReview-Commit-ID: KcKAXLxJr7l
mobile/android/base/java/org/mozilla/gecko/preferences/AndroidImport.java
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/AndroidImport.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/AndroidImport.java
@@ -146,24 +146,33 @@ public class AndroidImport implements Ru
         } finally {
             if (cursor != null)
                 cursor.close();
         }
 
         flushBatchOperations();
     }
 
-    protected Cursor query (Uri mainUri, Uri fallbackUri, String condition) {
-        Cursor cursor = mCr.query(mainUri, null, condition, null, null);
+    protected Cursor query(Uri mainUri, Uri fallbackUri, String condition) {
+        final Cursor cursor = mCr.query(mainUri, null, condition, null, null);
+        try {
+            if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && (cursor == null || cursor.getCount() == 0)) {
+                if (cursor != null) {
+                    cursor.close();
+                }
+                return mCr.query(fallbackUri, null, null, null, null);
+            }
+            return cursor;
 
-        if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && (cursor == null || cursor.getCount() == 0)) {
-            cursor = mCr.query(fallbackUri, null, null, null, null);
+        } catch (final Exception e) {
+            if (cursor != null) {
+                cursor.close();
+            }
+            throw e;
         }
-
-        return cursor;
     }
 
     protected void flushBatchOperations() {
         Log.d(LOGTAG, "Flushing " + mOperations.size() + " DB operations");
         try {
             // We don't really care for the results, this is best-effort.
             mCr.applyBatch(BrowserContract.AUTHORITY, mOperations);
         } catch (RemoteException e) {