From 85ebed2d1c2ef4a6ec4b10e49c2adcc83be2c34c Mon Sep 17 00:00:00 2001 From: Gian-Carlo Pascutto Date: Fri, 22 Nov 2013 09:54:45 +0100 Subject: [PATCH] Bug 932692 - Check for uncaught exceptions after JNI calls followed by JNI calls. r=blassey --- .../video_capture/android/device_info_android.cc | 4 ++-- .../video_capture/android/video_capture_android.cc | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc b/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc index a6ec7ad14c41..ac5467a7b710 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc @@ -105,7 +105,7 @@ int32_t DeviceInfoAndroid::GetDeviceName( if (cid != NULL) { jobject javaDeviceNameObj = env->CallObjectMethod(javaCmDevInfoObject, cid, deviceNumber); - if (javaDeviceNameObj == NULL) { + if (javaDeviceNameObj == NULL || jniFrame.CheckForException()) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "%s: Failed to get device name for device %d.", __FUNCTION__, (int) deviceNumber); @@ -200,7 +200,7 @@ int32_t DeviceInfoAndroid::CreateCapabilityMap( // Call the java class and get an array with capabilities back. jobject javaCapabilitiesObj = env->CallObjectMethod(javaCmDevInfoObject, cid, capureIdString); - if (!javaCapabilitiesObj) { + if (!javaCapabilitiesObj || jniFrame.CheckForException()) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "%s: Failed to call java GetCapabilityArray.", __FUNCTION__); diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc b/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc index c61d2671a005..2de9b441e121 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc @@ -154,7 +154,12 @@ int32_t VideoCaptureAndroid::SetAndroidObjects(void* javaVM, env->CallStaticObjectMethod(g_javaCmDevInfoClass, cid, (int) -1, javaContext); - if (!javaCameraDeviceInfoObjLocal) { + bool exceptionThrown = env->ExceptionCheck(); + if (!javaCameraDeviceInfoObjLocal || exceptionThrown) { + if (exceptionThrown) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } EARLY_WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideoCapture, -1, "%s: could not create Java Capture Device info object", __FUNCTION__); @@ -329,7 +334,7 @@ int32_t VideoCaptureAndroid::Init(const int32_t id, cid, (jint) id, (jlong) this, capureIdString); - if (!javaCameraObjLocal) { + if (!javaCameraObjLocal || jniFrame.CheckForException()) { WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideoCapture, _id, "%s: could not create Java Capture object", __FUNCTION__); return -1; @@ -372,6 +377,7 @@ VideoCaptureAndroid::~VideoCaptureAndroid() { "%s: Call DeleteVideoCaptureAndroid", __FUNCTION__); // Close the camera by calling the static destruct function. env->CallStaticVoidMethod(g_javaCmClass, cid, _javaCaptureObj); + jniFrame.CheckForException(); // Delete global object ref to the camera. env->DeleteGlobalRef(_javaCaptureObj);