close FileInputStreams to prevent resource leak

This commit is contained in:
davotoula
2025-09-06 16:31:22 +02:00
parent 16b5d44c3d
commit 9be55eda07
2 changed files with 5 additions and 3 deletions

View File

@@ -50,8 +50,10 @@ class CrashReportCache(
suspend fun loadAndDelete(): String? = suspend fun loadAndDelete(): String? =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val stack = val stack =
inputStreamOrNull()?.let { inStream -> inputStreamOrNull()?.use { inStream ->
InputStreamReader(inStream).readText() InputStreamReader(inStream).use { reader ->
reader.readText()
}
} }
deleteReport() deleteReport()
stack stack

View File

@@ -73,7 +73,7 @@ abstract class OpCrypto internal constructor() : OpUnary() {
} }
@Throws(IOException::class, NoSuchAlgorithmException::class) @Throws(IOException::class, NoSuchAlgorithmException::class)
fun hashFd(file: File?): ByteArray = hashFd(FileInputStream(file)) fun hashFd(file: File?): ByteArray = FileInputStream(file).use { inputStream -> hashFd(inputStream) }
@Throws(IOException::class, NoSuchAlgorithmException::class) @Throws(IOException::class, NoSuchAlgorithmException::class)
fun hashFd(bytes: ByteArray): ByteArray { fun hashFd(bytes: ByteArray): ByteArray {