Fix cursor leak when resolving contact photos

Closes #2933

// FREEBIE
This commit is contained in:
Jake McGinty 2015-04-09 17:01:43 -07:00 committed by Moxie Marlinspike
parent 568c69c9be
commit 77e846d24e

View File

@ -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);