From 77e846d24e27dcae41d64bf776d44be59a58d927 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Thu, 9 Apr 2015 17:01:43 -0700 Subject: [PATCH] Fix cursor leak when resolving contact photos Closes #2933 // FREEBIE --- .../securesms/contacts/ContactPhotoFactory.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java b/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java index 763d9f0a03..c41d3bbe38 100644 --- a/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java +++ b/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java @@ -10,7 +10,6 @@ import android.provider.ContactsContract.Contacts; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.util.BitmapUtil; import org.thoughtcrime.securesms.util.LRUCache; import java.io.InputStream; @@ -60,12 +59,15 @@ public class ContactPhotoFactory { if (contactPhoto == null) { Cursor cursor = context.getContentResolver().query(uri, CONTENT_URI_PROJECTION, null, null, null); - - if (cursor != null && cursor.moveToFirst()) { - contactPhoto = getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI, - cursor.getLong(0) + "")); - } else { - contactPhoto = getDefaultContactPhoto(context); + try { + if (cursor != null && cursor.moveToFirst()) { + contactPhoto = getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI, + cursor.getLong(0) + "")); + } else { + contactPhoto = getDefaultContactPhoto(context); + } + } finally { + if (cursor != null) cursor.close(); } localUserContactPhotoCache.put(uri, contactPhoto);