From b477272d653358fc6939af509a588ae5ed486499 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 11 Nov 2024 17:24:35 +0100 Subject: [PATCH] Close open FD after file export to avoid resource leaks --- .../java/sushi/hardcore/droidfs/EncryptedFileProvider.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/EncryptedFileProvider.kt b/app/src/main/java/sushi/hardcore/droidfs/EncryptedFileProvider.kt index f4837fa..494964e 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/EncryptedFileProvider.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/EncryptedFileProvider.kt @@ -160,8 +160,10 @@ class EncryptedFileProvider(context: Context) { exportedFile: ExportedFile, encryptedVolume: EncryptedVolume, ): Boolean { - val fd = exportedFile.open(ParcelFileDescriptor.MODE_WRITE_ONLY, false).fileDescriptor - return encryptedVolume.exportFile(exportedFile.path, FileOutputStream(fd)) + val pfd = exportedFile.open(ParcelFileDescriptor.MODE_WRITE_ONLY, false) + return encryptedVolume.exportFile(exportedFile.path, FileOutputStream(pfd.fileDescriptor)).also { + pfd.close() + } } enum class Error {