Skip to content

Commit d08c926

Browse files
committed
Making sure Cursor is closed if exception gets thrown.
1 parent ba751a2 commit d08c926

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/ImageUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,17 +406,17 @@ public static byte[] createThumbnailFromUri(Context context,
406406
String filePath = null;
407407
if (imageUri.toString().contains("content:")) {
408408
String[] projection = new String[] { MediaStore.Images.Media.DATA };
409+
Cursor cur = null;
409410
try {
410-
Cursor cur = context.getContentResolver().query(imageUri, projection, null, null, null);
411-
if (cur != null) {
412-
if (cur.moveToFirst()) {
413-
int dataColumn = cur.getColumnIndex(MediaStore.Images.Media.DATA);
414-
filePath = cur.getString(dataColumn);
415-
}
416-
cur.close();
411+
cur = context.getContentResolver().query(imageUri, projection, null, null, null);
412+
if (cur != null && cur.moveToFirst()) {
413+
int dataColumn = cur.getColumnIndex(MediaStore.Images.Media.DATA);
414+
filePath = cur.getString(dataColumn);
417415
}
418416
} catch (IllegalStateException stateException) {
419417
Log.d(ImageUtils.class.getName(), "IllegalStateException querying content:" + imageUri);
418+
} finally {
419+
SqlUtils.closeCursor(cur);
420420
}
421421
}
422422

0 commit comments

Comments
 (0)