avoid cursor leak in email provider

When cursor is done, the cursor must be closed to avoid cursor leak.

cherry-pick of https://android-review.googlesource.com/#/c/52910/
Change-Id: Iaaffed2c4e90dc4b17ae55fcedb242bf890b3dd5
This commit is contained in:
Yoohyun.choi 2013-03-06 10:08:58 +09:00 committed by Paul Westbrook
parent 156163cceb
commit 89c74e89e5
1 changed files with 14 additions and 10 deletions

View File

@ -1066,16 +1066,20 @@ public final class DBHelper {
Cursor c = db.query(Account.TABLE_NAME,
new String[] {EmailContent.RECORD_ID /*0*/, AccountColumns.SECURITY_FLAGS /*1*/},
AccountColumns.SECURITY_FLAGS + ">0", null, null, null, null);
ContentValues cv = new ContentValues();
String[] args = new String[1];
while (c.moveToNext()) {
long securityFlags = c.getLong(1 /*SECURITY_FLAGS*/);
Policy policy = LegacyPolicySet.flagsToPolicy(securityFlags);
long policyId = db.insert(Policy.TABLE_NAME, null, policy.toContentValues());
cv.put(AccountColumns.POLICY_KEY, policyId);
cv.putNull(AccountColumns.SECURITY_FLAGS);
args[0] = Long.toString(c.getLong(0 /*RECORD_ID*/));
db.update(Account.TABLE_NAME, cv, EmailContent.RECORD_ID + "=?", args);
try {
ContentValues cv = new ContentValues();
String[] args = new String[1];
while (c.moveToNext()) {
long securityFlags = c.getLong(1 /*SECURITY_FLAGS*/);
Policy policy = LegacyPolicySet.flagsToPolicy(securityFlags);
long policyId = db.insert(Policy.TABLE_NAME, null, policy.toContentValues());
cv.put(AccountColumns.POLICY_KEY, policyId);
cv.putNull(AccountColumns.SECURITY_FLAGS);
args[0] = Long.toString(c.getLong(0 /*RECORD_ID*/));
db.update(Account.TABLE_NAME, cv, EmailContent.RECORD_ID + "=?", args);
}
} finally {
c.close();
}
}