Skip to content

Commit 07f97bf

Browse files
committed
Android GUI: Fix contentResolver cursor may not be closed
1 parent 29f3d3f commit 07f97bf

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Source/GUI/Android/app/src/main/java/net/mediaarea/mediainfo/ReportViewModel.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ class ReportViewModel(private val dataSource: ReportDao) : ViewModel() {
6464
try {
6565
val cursor: Cursor? =
6666
contentResolver.query(uri, null, null, null, null, null)
67-
// moveToFirst() returns false if the cursor has 0 rows
68-
if (cursor != null && cursor.moveToFirst()) {
69-
// DISPLAY_NAME is provider-specific, and might not be the file name
70-
val column =
71-
cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)
72-
if (column >= 0) {
73-
displayName = cursor.getString(column)
67+
cursor?.use {
68+
// moveToFirst() returns false if the cursor has 0 rows
69+
if (cursor.moveToFirst()) {
70+
// DISPLAY_NAME is provider-specific, and might not be the file name
71+
val column =
72+
cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)
73+
if (column >= 0)
74+
displayName = cursor.getString(column)
7475
}
75-
cursor.close()
7676
}
7777
} catch (_: Exception) {
7878
}

0 commit comments

Comments
 (0)