diff options
author | Amith Yamasani <yamasani@google.com> | 2009-09-10 17:34:21 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2009-09-11 10:38:50 -0700 |
commit | 89233b778ef8e0af154ab2ff46a07658759e4838 (patch) | |
tree | 11739829daf3d08014b22d8b478e7ee72f37732e | |
parent | d360ccf9d865344871a18c57ac63c82c64bc03d9 (diff) | |
download | android_packages_providers_UserDictionaryProvider-89233b778ef8e0af154ab2ff46a07658759e4838.tar.gz android_packages_providers_UserDictionaryProvider-89233b778ef8e0af154ab2ff46a07658759e4838.tar.bz2 android_packages_providers_UserDictionaryProvider-89233b778ef8e0af154ab2ff46a07658759e4838.zip |
Fix a cursor leak when there is no data in the user dictionary.
-rw-r--r-- | src/com/android/providers/userdictionary/DictionaryBackupAgent.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/com/android/providers/userdictionary/DictionaryBackupAgent.java b/src/com/android/providers/userdictionary/DictionaryBackupAgent.java index 5eed461..a759e8b 100644 --- a/src/com/android/providers/userdictionary/DictionaryBackupAgent.java +++ b/src/com/android/providers/userdictionary/DictionaryBackupAgent.java @@ -145,8 +145,10 @@ public class DictionaryBackupAgent extends BackupHelperAgent { private byte[] getDictionary() { Cursor cursor = getContentResolver().query(Words.CONTENT_URI, PROJECTION, null, null, Words.WORD); + if (cursor == null) return EMPTY_DATA; if (!cursor.moveToFirst()) { Log.e(TAG, "Couldn't read from the cursor"); + cursor.close(); return EMPTY_DATA; } byte[] sizeBytes = new byte[4]; @@ -165,11 +167,12 @@ public class DictionaryBackupAgent extends BackupHelperAgent { gzip.write(line); cursor.moveToNext(); } - cursor.close(); gzip.finish(); } catch (IOException ioe) { Log.e(TAG, "Couldn't compress the dictionary:\n" + ioe); return EMPTY_DATA; + } finally { + cursor.close(); } return baos.toByteArray(); } |