Bug 641010 - crash [@ libdvm.so@0x35790][@ libdvm.so@0x35748 ][@ libdvm.so@0x35784 ][@ libdvm.so@0x357d0 ]. The way we were creating new java strings was leaky in a few places, and non-null terminated in others. This could/does results in a bunch of random crashes that will not show up in crash reporter. Basically, if you want to always make sure that you have a local frame and never use our low level string apis that don't terminate when creating java strings. r=mwu a=sheriff AURORA_BASE_20110524
authorDoug Turner <dougt@mozilla.com>
Tue, 24 May 2011 11:58:59 -0400
changeset 70107 9eae975b3d6fb7748fe5a3c0113d449b1c7cc0b2
parent 70106 575362d9b92e8c065014efc51bf76d692288f817
child 70108 f682047513f4ebf9455b1771be0d91ecb6577d1d
child 70886 2ee9b3a8c7c98f287c1b461c32d3c55bdd003bd2
push id20187
push userjlebar@mozilla.com
push dateTue, 24 May 2011 16:12:37 +0000
treeherdermozilla-central@9eae975b3d6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu, sheriff
bugs641010
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 641010 - crash [@ libdvm.so@0x35790][@ libdvm.so@0x35748 ][@ libdvm.so@0x35784 ][@ libdvm.so@0x357d0 ]. The way we were creating new java strings was leaky in a few places, and non-null terminated in others. This could/does results in a bunch of random crashes that will not show up in crash reporter. Basically, if you want to always make sure that you have a local frame and never use our low level string apis that don't terminate when creating java strings. r=mwu a=sheriff
widget/src/android/AndroidBridge.cpp
--- a/widget/src/android/AndroidBridge.cpp
+++ b/widget/src/android/AndroidBridge.cpp
@@ -385,19 +385,19 @@ AndroidBridge::GetHandlersForMimeType(co
                                       const nsAString& aAction)
 {
     ALOG_BRIDGE("AndroidBridge::GetHandlersForMimeType");
 
     AutoLocalJNIFrame jniFrame;
     NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
     jstring jstrMimeType =
         mJNIEnv->NewString(wMimeType.get(), wMimeType.Length());
-    const PRUnichar* wAction;
-    PRUint32 actionLen = NS_StringGetData(aAction, &wAction);
-    jstring jstrAction = mJNIEnv->NewString(wAction, actionLen);
+
+    jstring jstrAction = mJNIEnv->NewString(nsPromiseFlatString(aAction).get(),
+                                            aAction.Length());
 
     jobject obj = mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
                                                   jGetHandlersForMimeType,
                                                   jstrMimeType, jstrAction);
     jobjectArray arr = static_cast<jobjectArray>(obj);
     if (!arr)
         return PR_FALSE;
 
@@ -418,19 +418,18 @@ AndroidBridge::GetHandlersForURL(const c
                                       nsIHandlerApp **aDefaultApp,
                                       const nsAString& aAction)
 {
     ALOG_BRIDGE("AndroidBridge::GetHandlersForURL");
 
     AutoLocalJNIFrame jniFrame;
     NS_ConvertUTF8toUTF16 wScheme(aURL);
     jstring jstrScheme = mJNIEnv->NewString(wScheme.get(), wScheme.Length());
-    const PRUnichar* wAction;
-    PRUint32 actionLen = NS_StringGetData(aAction, &wAction);
-    jstring jstrAction = mJNIEnv->NewString(wAction, actionLen);
+    jstring jstrAction = mJNIEnv->NewString(nsPromiseFlatString(aAction).get(),
+                                            aAction.Length());
 
     jobject obj = mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
                                                   jGetHandlersForURL,
                                                   jstrScheme, jstrAction);
     jobjectArray arr = static_cast<jobjectArray>(obj);
     if (!arr)
         return PR_FALSE;
 
@@ -449,31 +448,28 @@ AndroidBridge::OpenUriExternal(const nsA
                                const nsAString& aPackageName, const nsAString& aClassName,
                                const nsAString& aAction, const nsAString& aTitle)
 {
     ALOG_BRIDGE("AndroidBridge::OpenUriExternal");
 
     AutoLocalJNIFrame jniFrame;
     NS_ConvertUTF8toUTF16 wUriSpec(aUriSpec);
     NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
-    const PRUnichar* wPackageName;
-    PRUint32 packageNameLen = NS_StringGetData(aPackageName, &wPackageName);
-    const PRUnichar* wClassName;
-    PRUint32 classNameLen = NS_StringGetData(aClassName, &wClassName);
-    const PRUnichar* wAction;
-    PRUint32 actionLen = NS_StringGetData(aAction, &wAction);
-    const PRUnichar* wTitle;
-    PRUint32 titleLen = NS_StringGetData(aTitle, &wTitle);
 
     jstring jstrUri = mJNIEnv->NewString(wUriSpec.get(), wUriSpec.Length());
     jstring jstrType = mJNIEnv->NewString(wMimeType.get(), wMimeType.Length());
-    jstring jstrPackage = mJNIEnv->NewString(wPackageName, packageNameLen);
-    jstring jstrClass = mJNIEnv->NewString(wClassName, classNameLen);
-    jstring jstrAction = mJNIEnv->NewString(wAction, actionLen);
-    jstring jstrTitle = mJNIEnv->NewString(wTitle, titleLen);
+
+    jstring jstrPackage = mJNIEnv->NewString(nsPromiseFlatString(aPackageName).get(),
+                                             aPackageName.Length());
+    jstring jstrClass = mJNIEnv->NewString(nsPromiseFlatString(aClassName).get(),
+                                           aClassName.Length());
+    jstring jstrAction = mJNIEnv->NewString(nsPromiseFlatString(aAction).get(),
+                                            aAction.Length());
+    jstring jstrTitle = mJNIEnv->NewString(nsPromiseFlatString(aTitle).get(),
+                                           aTitle.Length());
 
     return mJNIEnv->CallStaticBooleanMethod(mGeckoAppShellClass,
                                             jOpenUriExternal,
                                             jstrUri, jstrType, jstrPackage, 
                                             jstrClass, jstrAction, jstrTitle);
 }
 
 void
@@ -530,20 +526,19 @@ AndroidBridge::GetClipboardText(nsAStrin
     aText.Assign(jniStr);
     return PR_TRUE;
 }
 
 void
 AndroidBridge::SetClipboardText(const nsAString& aText)
 {
     ALOG_BRIDGE("AndroidBridge::SetClipboardText");
-
-    const PRUnichar* wText;
-    PRUint32 wTextLen = NS_StringGetData(aText, &wText);
-    jstring jstr = mJNIEnv->NewString(wText, wTextLen);
+    AutoLocalJNIFrame jniFrame;
+    jstring jstr = mJNIEnv->NewString(nsPromiseFlatString(aText).get(),
+                                      aText.Length());
     mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass, jSetClipboardText, jstr);
 }
 
 bool
 AndroidBridge::ClipboardHasText()
 {
     ALOG_BRIDGE("AndroidBridge::ClipboardHasText");
 
@@ -672,16 +667,17 @@ AndroidBridge::IsNetworkLinkKnown()
     ALOG_BRIDGE("AndroidBridge::IsNetworkLinkKnown");
     return !!mJNIEnv->CallStaticBooleanMethod(mGeckoAppShellClass, jIsNetworkLinkKnown);
 }
 
 void
 AndroidBridge::SetSelectedLocale(const nsAString& aLocale)
 {
     ALOG_BRIDGE("AndroidBridge::SetSelectedLocale");
+    AutoLocalJNIFrame jniFrame;
     jstring jLocale = GetJNIForThread()->NewString(PromiseFlatString(aLocale).get(), aLocale.Length());
     GetJNIForThread()->CallStaticVoidMethod(mGeckoAppShellClass, jSetSelectedLocale, jLocale);
 }
 
 void
 AndroidBridge::GetSystemColors(AndroidSystemColors *aColors)
 {
     ALOG_BRIDGE("AndroidBridge::GetSystemColors");
@@ -850,16 +846,17 @@ extern "C" JNIEnv * GetJNIForThread()
 jclass GetGeckoAppShellClass()
 {
     return mozilla::AndroidBridge::GetGeckoAppShellClass();
 }
 
 void
 AndroidBridge::ScanMedia(const nsAString& aFile, const nsACString& aMimeType)
 {
+    AutoLocalJNIFrame jniFrame;
     jstring jstrFile = mJNIEnv->NewString(nsPromiseFlatString(aFile).get(), aFile.Length());
 
     nsString mimeType2;
     CopyUTF8toUTF16(aMimeType, mimeType2);
     jstring jstrMimeTypes = mJNIEnv->NewString(nsPromiseFlatString(mimeType2).get(), mimeType2.Length());
 
     mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jScanMedia, jstrFile, jstrMimeTypes);
 }