Fix missing Release for GetStringUTFChars calls.

Bug: 230122201

Test: No leaks detected in these code paths.
Test: atest android.hardware.camera2.cts.DngCreatorTest on pixel 6 Pro.
Change-Id: I135739b9e65a57c3d130c35fcdf4ffd1ec4786c0
This commit is contained in:
Christopher Ferris
2022-04-21 21:31:35 -07:00
committed by Elliott Hughes
parent 3f28fc9946
commit 813714c2e3
2 changed files with 9 additions and 6 deletions

View File

@@ -459,8 +459,12 @@ static jobject NativeGetOverlayableInfo(JNIEnv* env, jclass /*clazz*/, jlong ptr
return nullptr;
}
auto overlayable_name_native = std::string(env->GetStringUTFChars(overlayable_name, NULL));
const char* overlayable_name_native = env->GetStringUTFChars(overlayable_name, nullptr);
if (overlayable_name_native == nullptr) {
return nullptr;
}
auto actor = overlayable_map.find(overlayable_name_native);
env->ReleaseStringUTFChars(overlayable_name, overlayable_name_native);
if (actor == overlayable_map.end()) {
return nullptr;
}

View File

@@ -48,6 +48,7 @@
#include <jni.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/ScopedUtfChars.h>
using namespace android;
using namespace img_utils;
@@ -1264,16 +1265,14 @@ static void DngCreator_init(JNIEnv* env, jobject thiz, jobject characteristicsPt
sp<NativeContext> nativeContext = new NativeContext(characteristics, results);
const char* captureTime = env->GetStringUTFChars(formattedCaptureTime, nullptr);
size_t len = strlen(captureTime) + 1;
if (len != NativeContext::DATETIME_COUNT) {
ScopedUtfChars captureTime(env, formattedCaptureTime);
if (captureTime.size() + 1 != NativeContext::DATETIME_COUNT) {
jniThrowException(env, "java/lang/IllegalArgumentException",
"Formatted capture time string length is not required 20 characters");
return;
}
nativeContext->setCaptureTime(String8(captureTime));
nativeContext->setCaptureTime(String8(captureTime.c_str()));
DngCreator_setNativeContext(env, thiz, nativeContext);
}