提交 ca3be996 编写于 作者: O olly 提交者: Oliver Woodman

Add proper exception checks when returning to native from Java.

The pending exception will be thrown upon returning to Java
from native, but we should return early rather than continuing
to execute the native method to the end so as to avoid undefined
behavior. Note that the return value is irrelevant (because the
pending exception will be thrown).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184119606
上级 1bf49263
......@@ -50,7 +50,8 @@ class JavaDataSource : public DataSource {
ssize_t readAt(off64_t offset, void *const data, size_t size) {
jobject byteBuffer = env->NewDirectByteBuffer(data, size);
int result = env->CallIntMethod(flacDecoderJni, mid, byteBuffer);
if (env->ExceptionOccurred()) {
if (env->ExceptionCheck()) {
// Exception is thrown in Java when returning from the native call.
result = -1;
}
env->DeleteLocalRef(byteBuffer);
......
......@@ -103,8 +103,16 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
kMaxOpusOutputPacketSizeSamples * kBytesPerSample * channelCount;
env->CallObjectMethod(jOutputBuffer, outputBufferInit, jTimeUs, outputSize);
if (env->ExceptionCheck()) {
// Exception is thrown in Java when returning from the native call.
return -1;
}
const jobject jOutputBufferData = env->CallObjectMethod(jOutputBuffer,
outputBufferInit, jTimeUs, outputSize);
if (env->ExceptionCheck()) {
// Exception is thrown in Java when returning from the native call.
return -1;
}
int16_t* outputBufferData = reinterpret_cast<int16_t*>(
env->GetDirectBufferAddress(jOutputBufferData));
......
......@@ -362,7 +362,7 @@ DECODER_FUNC(jint, vpxGetFrame, jlong jContext, jobject jOutputBuffer) {
// resize buffer if required.
jboolean initResult = env->CallBooleanMethod(jOutputBuffer, initForRgbFrame,
img->d_w, img->d_h);
if (initResult == JNI_FALSE) {
if (env->ExceptionCheck() || !initResult) {
return -1;
}
......@@ -400,7 +400,7 @@ DECODER_FUNC(jint, vpxGetFrame, jlong jContext, jobject jOutputBuffer) {
jboolean initResult = env->CallBooleanMethod(
jOutputBuffer, initForYuvFrame, img->d_w, img->d_h,
img->stride[VPX_PLANE_Y], img->stride[VPX_PLANE_U], colorspace);
if (initResult == JNI_FALSE) {
if (env->ExceptionCheck() || !initResult) {
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册