From 9be55eda078428200bb14d55570f0591946c562f Mon Sep 17 00:00:00 2001 From: davotoula Date: Sat, 6 Sep 2025 16:31:22 +0200 Subject: [PATCH] close FileInputStreams to prevent resource leak --- .../amethyst/service/crashreports/CrashReportCache.kt | 6 ++++-- .../vitorpamplona/quartz/nip03Timestamp/ots/op/OpCrypto.kt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/crashreports/CrashReportCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/crashreports/CrashReportCache.kt index cef894441..cdf050b32 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/crashreports/CrashReportCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/crashreports/CrashReportCache.kt @@ -50,8 +50,10 @@ class CrashReportCache( suspend fun loadAndDelete(): String? = withContext(Dispatchers.IO) { val stack = - inputStreamOrNull()?.let { inStream -> - InputStreamReader(inStream).readText() + inputStreamOrNull()?.use { inStream -> + InputStreamReader(inStream).use { reader -> + reader.readText() + } } deleteReport() stack diff --git a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpCrypto.kt b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpCrypto.kt index a54907c44..888a6e8d7 100644 --- a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpCrypto.kt +++ b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpCrypto.kt @@ -73,7 +73,7 @@ abstract class OpCrypto internal constructor() : OpUnary() { } @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) fun hashFd(bytes: ByteArray): ByteArray {