diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-06-17 20:26:06 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-06-17 20:26:06 +0200 |
commit | 5895385153aa1b56717495b816238961d03023a5 (patch) | |
tree | 49c264ef05d7dbfd3059595a764fe8a10b32031c /OpenKeychain/src/main | |
parent | 300fd8e0f26c328aa351318fdea17485d2d940d4 (diff) | |
download | open-keychain-5895385153aa1b56717495b816238961d03023a5.tar.gz open-keychain-5895385153aa1b56717495b816238961d03023a5.tar.bz2 open-keychain-5895385153aa1b56717495b816238961d03023a5.zip |
fix a couple of resource leaks (#1351)
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java | 13 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java | 25 |
2 files changed, 23 insertions, 15 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index e1efd5abc..77aa1a055 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -303,10 +303,13 @@ public class ContactHelper { Cursor contactMasterKey = context.getContentResolver().query(contactUri, new String[]{ContactsContract.Data.DATA2}, null, null, null); if (contactMasterKey != null) { - if (contactMasterKey.moveToNext()) { - return KeychainContract.KeyRings.buildGenericKeyRingUri(contactMasterKey.getLong(0)); + try { + if (contactMasterKey.moveToNext()) { + return KeychainContract.KeyRings.buildGenericKeyRingUri(contactMasterKey.getLong(0)); + } + } finally { + contactMasterKey.close(); } - 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) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java index 5a314ad0b..eabbf83b8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java @@ -66,21 +66,24 @@ public class ParcelableFileCache<E extends Parcelable> { File tempFile = new File(mContext.getCacheDir(), mFilename); - DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile)); - oos.writeInt(numEntries); + DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile)); - while (it.hasNext()) { - Parcel p = Parcel.obtain(); // creating empty parcel object - p.writeParcelable(it.next(), 0); // saving bundle as parcel - byte[] buf = p.marshall(); - oos.writeInt(buf.length); - oos.write(buf); - p.recycle(); + try { + oos.writeInt(numEntries); + + while (it.hasNext()) { + Parcel p = Parcel.obtain(); // creating empty parcel object + p.writeParcelable(it.next(), 0); // saving bundle as parcel + byte[] buf = p.marshall(); + oos.writeInt(buf.length); + oos.write(buf); + p.recycle(); + } + } finally { + oos.close(); } - oos.close(); - } /** |