summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-04-25 10:45:04 -0700
committerJeff Sharkey <jsharkey@android.com>2013-04-25 10:45:04 -0700
commit361f35b7b1fe758d93e0952536a298b2ed045a89 (patch)
tree27ae11d0487e541d4a76ac820af27cf78c406896
parentc387029cf67358eea21f9fd60e6cac60049839b7 (diff)
downloadandroid_packages_providers_UserDictionaryProvider-361f35b7b1fe758d93e0952536a298b2ed045a89.tar.gz
android_packages_providers_UserDictionaryProvider-361f35b7b1fe758d93e0952536a298b2ed045a89.tar.bz2
android_packages_providers_UserDictionaryProvider-361f35b7b1fe758d93e0952536a298b2ed045a89.zip
Close stream after writing backup data.
Avoids leak. Change-Id: I657044d1ecc98c021271dab486e104d74f60cc5c
-rw-r--r--src/com/android/providers/userdictionary/DictionaryBackupAgent.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/com/android/providers/userdictionary/DictionaryBackupAgent.java b/src/com/android/providers/userdictionary/DictionaryBackupAgent.java
index 6432a01..d4bf885 100644
--- a/src/com/android/providers/userdictionary/DictionaryBackupAgent.java
+++ b/src/com/android/providers/userdictionary/DictionaryBackupAgent.java
@@ -41,6 +41,8 @@ import android.provider.UserDictionary.Words;
import android.text.TextUtils;
import android.util.Log;
+import libcore.io.IoUtils;
+
/**
* Performs backup and restore of the User Dictionary.
*/
@@ -156,8 +158,9 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
}
byte[] sizeBytes = new byte[4];
ByteArrayOutputStream baos = new ByteArrayOutputStream(cursor.getCount() * 10);
+ GZIPOutputStream gzip = null;
try {
- GZIPOutputStream gzip = new GZIPOutputStream(baos);
+ gzip = new GZIPOutputStream(baos);
while (!cursor.isAfterLast()) {
String name = cursor.getString(COLUMN_WORD);
int frequency = cursor.getInt(COLUMN_FREQUENCY);
@@ -179,6 +182,7 @@ public class DictionaryBackupAgent extends BackupAgentHelper {
Log.e(TAG, "Couldn't compress the dictionary:\n" + ioe);
return EMPTY_DATA;
} finally {
+ IoUtils.closeQuietly(gzip);
cursor.close();
}
return baos.toByteArray();