From b4d178df818e8b6e7a1cfbb0e34bbf7bb9d74ec9 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 12 May 2011 12:48:14 +0100 Subject: Always check weak global references before using them We hold weak references to Java objects from native code in several places to avoid circular reference problems. These objects may become weakly reachable at any time, after which the GC could null our weak reference, so we have to null-check at every use. Note that weak references are nulled before the referent is finalized, so we can't rely on doing work in the finalizer to wait for the currently executing message to complete and to remove other messages from the queue. This effectively reverts https://android-git.corp.google.com/g/#change,30955 Bug: 4336862 Change-Id: I431fcac11220cb406c26e31aacb9bda7ea22776e --- .../android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp') diff --git a/Source/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp b/Source/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp index 1e51989..ae8bec8 100644 --- a/Source/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp +++ b/Source/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp @@ -345,11 +345,12 @@ public: FrameView* frameView = m_player->frameView(); if (!frameView) return; - WebViewCore* webViewCore = WebViewCore::getWebViewCore(frameView); - ASSERT(webViewCore); + AutoJObject javaObject = WebViewCore::getWebViewCore(frameView)->getJavaObject(); + if (!javaObject.get()) + return; // Get the HTML5VideoViewProxy instance - obj = env->CallStaticObjectMethod(clazz, m_glue->m_getInstance, webViewCore->getJavaObject().get(), this); + obj = env->CallStaticObjectMethod(clazz, m_glue->m_getInstance, javaObject.get(), this); m_glue->m_javaProxy = env->NewGlobalRef(obj); // Send the poster jstring jUrl = 0; @@ -361,8 +362,7 @@ public: env->DeleteLocalRef(jUrl); // Clean up. - if (obj) - env->DeleteLocalRef(obj); + env->DeleteLocalRef(obj); env->DeleteLocalRef(clazz); checkException(env); } -- cgit v1.1