You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/10/02 10:07:55 UTC

[GitHub] YorkShen closed pull request #1612: [core] release char* to jni after using

YorkShen closed pull request #1612: [core] release char* to jni after using
URL: https://github.com/apache/incubator-weex/pull/1612
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/weex_core/Source/android/base/string/string_utils.h b/weex_core/Source/android/base/string/string_utils.h
index d09fd783af..6b42baec8e 100644
--- a/weex_core/Source/android/base/string/string_utils.h
+++ b/weex_core/Source/android/base/string/string_utils.h
@@ -64,8 +64,8 @@ static inline std::string jString2Str(JNIEnv *env, const jstring &jstr) {
 static inline std::string jString2StrFast(JNIEnv *env, const jstring &jstr){
   if (jstr == nullptr)
     return std::string("");
-  const char *nativeString = env->GetStringUTFChars(jstr, JNI_FALSE);
-  return std::string(nativeString);
+  auto nativeString = ScopedJStringUTF8(env, jstr);
+  return std::string(nativeString.getChars());
 }
 
 static std::string jByteArray2Str(JNIEnv *env, jbyteArray barr) {
diff --git a/weex_core/Source/android/wrap/wx_bridge.cpp b/weex_core/Source/android/wrap/wx_bridge.cpp
index a97d927388..e783eeeb13 100644
--- a/weex_core/Source/android/wrap/wx_bridge.cpp
+++ b/weex_core/Source/android/wrap/wx_bridge.cpp
@@ -170,10 +170,13 @@ static jlongArray GetRenderFinishTime(JNIEnv* env, jobject jcaller,
 
 // Notice that this method is invoked from main thread.
 static jboolean NotifyLayout(JNIEnv* env, jobject jcaller, jstring instanceId) {
-  return WeexCoreManager::Instance()
-      ->getPlatformBridge()
-      ->core_side()
-      ->NotifyLayout(jString2StrFast(env, instanceId));
+  if (WeexCoreManager::Instance()->getPlatformBridge()) {
+    return WeexCoreManager::Instance()
+        ->getPlatformBridge()
+        ->core_side()
+        ->NotifyLayout(jString2StrFast(env, instanceId));
+  }
+  return false;
 }
 
 // Notice that this method is invoked from JS thread.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services