From 156c4da2b31d91a725644dbd2d82bb1a276a9a68 Mon Sep 17 00:00:00 2001 From: maxim432 Date: Sat, 30 Jan 2021 17:56:54 -0800 Subject: [PATCH 1/2] Fix couple of leaks --- .../java/eu/siacs/conversations/persistance/FileBackend.java | 4 +++- .../siacs/conversations/services/XmppConnectionService.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 10421a27d..a49f2e497 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -1295,7 +1295,9 @@ public class FileBackend { private int calcSampleSize(Uri image, int size) throws FileNotFoundException, SecurityException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(image), null, options); + InputStream inputStream = mXmppConnectionService.getContentResolver().openInputStream(image); + BitmapFactory.decodeStream(inputStream, null, options); + close(inputStream); return calcSampleSize(options, size); } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 05ec26d67..3cf5aa9d1 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1241,6 +1241,7 @@ public class XmppConnectionService extends Service { public void onDestroy() { try { unregisterReceiver(this.mInternalEventReceiver); + unregisterReceiver(this.mInternalScreenEventReceiver); } catch (final IllegalArgumentException e) { //ignored } From 358c70828f62b72a86f90a4ef9b19531f9e94413 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 31 Jan 2021 10:13:20 +0100 Subject: [PATCH 2/2] close inputstream in image meta data analysers --- .../persistance/FileBackend.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index a49f2e497..f8714a526 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -601,12 +601,12 @@ public class FileBackend { } } - public boolean useImageAsIs(Uri uri) { - String path = getOriginalPath(uri); + public boolean useImageAsIs(final Uri uri) { + final String path = getOriginalPath(uri); if (path == null || isPathBlacklisted(path)) { return false; } - File file = new File(path); + final File file = new File(path); long size = file.length(); if (size == 0 || size >= mXmppConnectionService.getResources().getInteger(R.integer.auto_accept_filesize)) { return false; @@ -614,12 +614,15 @@ public class FileBackend { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; try { - BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(uri), null, options); + final InputStream inputStream = mXmppConnectionService.getContentResolver().openInputStream(uri); + BitmapFactory.decodeStream(inputStream, null, options); + close(inputStream); if (options.outMimeType == null || options.outHeight <= 0 || options.outWidth <= 0) { return false; } return (options.outWidth <= Config.IMAGE_SIZE && options.outHeight <= Config.IMAGE_SIZE && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase())); } catch (FileNotFoundException e) { + Log.d(Config.LOGTAG, "unable to get image dimensions", e); return false; } } @@ -796,14 +799,17 @@ public class FileBackend { updateFileParams(message); } - public boolean unusualBounds(Uri image) { + public boolean unusualBounds(final Uri image) { try { - BitmapFactory.Options options = new BitmapFactory.Options(); + final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(image), null, options); + final InputStream inputStream = mXmppConnectionService.getContentResolver().openInputStream(image); + BitmapFactory.decodeStream(inputStream, null, options); + close(inputStream); float ratio = (float) options.outHeight / options.outWidth; return ratio > (21.0f / 9.0f) || ratio < (9.0f / 21.0f); - } catch (Exception e) { + } catch (final Exception e) { + Log.w(Config.LOGTAG, "unable to detect image bounds", e); return false; } } @@ -1293,9 +1299,9 @@ public class FileBackend { } private int calcSampleSize(Uri image, int size) throws FileNotFoundException, SecurityException { - BitmapFactory.Options options = new BitmapFactory.Options(); + final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - InputStream inputStream = mXmppConnectionService.getContentResolver().openInputStream(image); + final InputStream inputStream = mXmppConnectionService.getContentResolver().openInputStream(image); BitmapFactory.decodeStream(inputStream, null, options); close(inputStream); return calcSampleSize(options, size);