From be4dfa4543118ffaff64c86198e6da72ee586046 Mon Sep 17 00:00:00 2001 From: Konstantin Tskhovrebov Date: Thu, 20 Jun 2024 15:37:53 +0200 Subject: [PATCH] [resources] Properly close input stream when read resource bytes. --- .../org/jetbrains/compose/resources/ResourceReader.android.kt | 2 +- .../org/jetbrains/compose/resources/ResourceReader.desktop.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt index be92557588..d8e5741966 100644 --- a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt +++ b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt @@ -18,7 +18,7 @@ internal actual fun getPlatformResourceReader(): ResourceReader = object : Resou override suspend fun read(path: String): ByteArray { val resource = getResourceAsStream(path) - return resource.readBytes() + return resource.use { input -> input.readBytes() } } override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray { diff --git a/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt b/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt index da70a3899c..f90b9d516c 100644 --- a/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt +++ b/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt @@ -5,7 +5,7 @@ import java.io.InputStream internal actual fun getPlatformResourceReader(): ResourceReader = object : ResourceReader { override suspend fun read(path: String): ByteArray { val resource = getResourceAsStream(path) - return resource.readBytes() + return resource.use { input -> input.readBytes() } } override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray {