From a5292aa669c180458f26bedcffd2cce19fd54e83 Mon Sep 17 00:00:00 2001 From: gmasil <54176035+gmasil@users.noreply.github.com> Date: Fri, 25 Aug 2023 13:27:19 +0200 Subject: [PATCH] close inputstream and datasource to prevent leaks --- .../gallery/pro/fragments/PhotoFragment.kt | 16 ++++++++-------- .../gallery/pro/fragments/VideoFragment.kt | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index b4f3bc143..9ef301107 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -740,18 +740,18 @@ class PhotoFragment : ViewPagerFragment() { } private fun checkIfPanorama() { - mIsPanorama = try { - val inputStream = if (mMedium.path.startsWith("content:/")) { + mIsPanorama = try { + if (mMedium.path.startsWith("content:/")) { requireContext().contentResolver.openInputStream(Uri.parse(mMedium.path)) } else { File(mMedium.path).inputStream() + }.use { + val imageParser = JpegImageParser().getXmpXml(ByteSourceInputStream(it, mMedium.name), HashMap()) + imageParser.contains("GPano:UsePanoramaViewer=\"True\"", true) || + imageParser.contains("True", true) || + imageParser.contains("GPano:FullPanoWidthPixels=") || + imageParser.contains("GPano:ProjectionType>Equirectangular") } - - val imageParser = JpegImageParser().getXmpXml(ByteSourceInputStream(inputStream, mMedium.name), HashMap()) - imageParser.contains("GPano:UsePanoramaViewer=\"True\"", true) || - imageParser.contains("True", true) || - imageParser.contains("GPano:FullPanoWidthPixels=") || - imageParser.contains("GPano:ProjectionType>Equirectangular") } catch (e: Exception) { false } catch (e: OutOfMemoryError) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt index a6baa9369..6b4b44557 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt @@ -362,6 +362,7 @@ import java.io.FileInputStream try { fileDataSource.open(dataSpec) } catch (e: Exception) { + fileDataSource.close() activity?.showErrorToast(e) return } @@ -370,6 +371,8 @@ import java.io.FileInputStream val mediaSource: MediaSource = ProgressiveMediaSource.Factory(factory) .createMediaSource(MediaItem.fromUri(fileDataSource.uri!!)) + fileDataSource.close() + mPlayOnPrepared = true mExoPlayer = ExoPlayer.Builder(requireContext())