Bug 1247557 - avoid memory leak by closing cursor before being initialized for the 2nd time. r?mcomella
MozReview-Commit-ID: dzYYakBDMK
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/AndroidImport.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/AndroidImport.java
@@ -147,23 +147,30 @@ public class AndroidImport implements Ru
if (cursor != null)
cursor.close();
}
flushBatchOperations();
}
protected Cursor query (Uri mainUri, Uri fallbackUri, String condition) {
- Cursor cursor = mCr.query(mainUri, null, condition, null, null);
+ Cursor cursor = null;
+ try {
+ cursor = mCr.query(mainUri, null, condition, null, null);
- if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && (cursor == null || cursor.getCount() == 0)) {
- cursor = mCr.query(fallbackUri, null, null, null, null);
+ if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && (cursor == null || cursor.getCount() == 0)) {
+ if (cursor != null) {
+ cursor.close();
+ }
+ cursor = mCr.query(fallbackUri, null, null, null, null);
+ }
}
-
- return cursor;
+ finally {
+ 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) {