Skip to content

Commit 1cad543

Browse files
committed
Fix resource leak
1 parent 545fc85 commit 1cad543

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,16 @@ class MainActivity : SimpleActivity() {
869869
}
870870

871871
private fun checkUri(uri: Uri, onChecksPassed: () -> Unit) {
872-
val inputStream = try {
873-
contentResolver.openInputStream(uri) ?: return
872+
try {
873+
contentResolver.openInputStream(uri)?.use { inputStream ->
874+
if (inputStream.available() > 1000 * 1000) {
875+
toast(R.string.file_too_large)
876+
} else {
877+
onChecksPassed()
878+
}
879+
} ?: return
874880
} catch (e: Exception) {
875881
showErrorToast(e)
876-
return
877-
}
878-
879-
if (inputStream.available() > 1000 * 1000) {
880-
toast(R.string.file_too_large)
881-
} else {
882-
onChecksPassed()
883882
}
884883
}
885884

0 commit comments

Comments
 (0)