From bbfabaf9305a5a7a058fe684f9e5de6d814200dc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 30 Sep 2017 15:50:01 +0200 Subject: [PATCH] FileBackend: close cursor after retrieving file size --- .../conversations/persistance/FileBackend.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index f6544fd0a..28fad15c3 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -138,10 +138,16 @@ public class FileBackend { } private static long getFileSize(Context context, Uri uri) { - Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); - } else { + try { + final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); + cursor.close(); + return size; + } else { + return -1; + } + } catch (Exception e) { return -1; } }