From ecfa5d346af2a231fcd7fe1b1f13cd959f4adcc3 Mon Sep 17 00:00:00 2001 From: SessionHero01 <180888785+SessionHero01@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:24:48 +1100 Subject: [PATCH] Close cursor in retrieveConfigLastUpdateTimestamp (#1692) --- .../securesms/database/ConfigDatabase.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt index 19a511bfd6..f95d62db11 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt @@ -44,10 +44,14 @@ class ConfigDatabase(context: Context, helper: SQLCipherOpenHelper): Database(co } fun retrieveConfigLastUpdateTimestamp(variant: String, publicKey: String): Long { - val db = readableDatabase - val cursor = db.query(TABLE_NAME, arrayOf(TIMESTAMP), VARIANT_AND_PUBKEY_WHERE, arrayOf(variant, publicKey),null, null, null) - if (cursor == null) return 0 - if (!cursor.moveToFirst()) return 0 - return (cursor.getLongOrNull(cursor.getColumnIndex(TIMESTAMP)) ?: 0) + return readableDatabase + .query(TABLE_NAME, arrayOf(TIMESTAMP), VARIANT_AND_PUBKEY_WHERE, arrayOf(variant, publicKey), null, null, null) + ?.use { cursor -> + if (cursor.moveToFirst()) { + cursor.getLongOrNull(cursor.getColumnIndex(TIMESTAMP)) + } else { + null + } + } ?: 0L } } \ No newline at end of file