1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-11 21:58:35 -05:00

Issue 395

Fix database connection leak
This commit is contained in:
Daniel Applebaum 2009-05-02 00:37:22 +00:00
parent d34b8119f6
commit b603d899db

View File

@ -94,8 +94,9 @@ public class Storage implements SharedPreferences
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
Log.i(Email.LOG_TAG, "Loading preferences from DB into Storage"); Log.i(Email.LOG_TAG, "Loading preferences from DB into Storage");
Cursor cursor = null; Cursor cursor = null;
SQLiteDatabase mDb = null;
try { try {
SQLiteDatabase mDb = openDB(); mDb = openDB();
cursor = mDb.rawQuery("SELECT primkey, value FROM preferences_storage", null); cursor = mDb.rawQuery("SELECT primkey, value FROM preferences_storage", null);
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
@ -112,6 +113,10 @@ public class Storage implements SharedPreferences
if (cursor != null) { if (cursor != null) {
cursor.close(); cursor.close();
} }
if (mDb != null)
{
mDb.close();
}
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
Log.i(Email.LOG_TAG, "Preferences load took " + (endTime - startTime) + "ms"); Log.i(Email.LOG_TAG, "Preferences load took " + (endTime - startTime) + "ms");
} }
@ -193,6 +198,10 @@ public class Storage implements SharedPreferences
workingStorage.remove(); workingStorage.remove();
workingChangedKeys.remove(); workingChangedKeys.remove();
mDb.endTransaction(); mDb.endTransaction();
if (mDb != null)
{
mDb.close();
}
} }
} }