From 07873d4e21abef477efafb253922f25a1c96746c Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 23 Jun 2022 16:15:04 -0700 Subject: [PATCH] Delete local JNI references created within AndroidImageGenerator::DoDecodeImage (flutter/engine#34148) --- .../platform/android/android_image_generator.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/android_image_generator.cc b/engine/src/flutter/shell/platform/android/android_image_generator.cc index d5255af97b..d3bb70f60d 100644 --- a/engine/src/flutter/shell/platform/android/android_image_generator.cc +++ b/engine/src/flutter/shell/platform/android/android_image_generator.cc @@ -96,14 +96,17 @@ void AndroidImageGenerator::DoDecodeImage() { JNIEnv* env = fml::jni::AttachCurrentThread(); - fml::jni::ScopedJavaLocalRef direct_buffer( - env, env->NewDirectByteBuffer(const_cast(data_->data()), - data_->size())); + // This task is run on the IO thread. Create a frame to ensure that all + // local JNI references used here are freed. + fml::jni::ScopedJavaLocalFrame scoped_local_reference_frame(env); + + jobject direct_buffer = + env->NewDirectByteBuffer(const_cast(data_->data()), data_->size()); auto bitmap = std::make_unique>( - env, env->CallStaticObjectMethod( - g_flutter_jni_class->obj(), g_decode_image_method, - direct_buffer.obj(), reinterpret_cast(this))); + env, env->CallStaticObjectMethod(g_flutter_jni_class->obj(), + g_decode_image_method, direct_buffer, + reinterpret_cast(this))); FML_CHECK(fml::jni::CheckException(env)); if (bitmap->is_null()) {