fix a couple of resource leaks (#1351)

This commit is contained in:
Vincent Breitmoser 2015-06-17 20:26:06 +02:00
parent 300fd8e0f2
commit 5895385153
2 changed files with 22 additions and 14 deletions

View File

@ -303,11 +303,14 @@ public class ContactHelper {
Cursor contactMasterKey = context.getContentResolver().query(contactUri,
new String[]{ContactsContract.Data.DATA2}, null, null, null);
if (contactMasterKey != null) {
try {
if (contactMasterKey.moveToNext()) {
return KeychainContract.KeyRings.buildGenericKeyRingUri(contactMasterKey.getLong(0));
}
} finally {
contactMasterKey.close();
}
}
return null;
}
@ -537,7 +540,7 @@ public class ContactHelper {
KEYS_TO_CONTACT_PROJECTION,
KeychainContract.KeyRings.HAS_ANY_SECRET + "!=0",
null, null);
if (cursor != null) {
if (cursor != null) try {
while (cursor.moveToNext()) {
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
@ -565,6 +568,8 @@ public class ContactHelper {
}
}
}
} finally {
cursor.close();
}
for (long masterKeyId : keysToDelete) {

View File

@ -66,8 +66,10 @@ public class ParcelableFileCache<E extends Parcelable> {
File tempFile = new File(mContext.getCacheDir(), mFilename);
DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile));
try {
oos.writeInt(numEntries);
while (it.hasNext()) {
@ -78,8 +80,9 @@ public class ParcelableFileCache<E extends Parcelable> {
oos.write(buf);
p.recycle();
}
} finally {
oos.close();
}
}