changeset 5266:60ad6d456028

RT-31943: Gtk: jni_GetStringUTFChars segfault while running in jruby/jrubyfx Reviewed-by: Alexander Zvegintsev <alexander.zvegintsev@oracle.com>
author Anthony Petrov <anthony.petrov@oracle.com>
date Fri, 04 Oct 2013 15:53:19 +0400
parents 7a8c5feb8c49
children 080c7905568c
files modules/graphics/src/main/native-glass/gtk/glass_general.h modules/graphics/src/main/native-glass/gtk/glass_screen.cpp
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/gtk/glass_general.h	Fri Oct 04 10:53:17 2013 +0200
+++ b/modules/graphics/src/main/native-glass/gtk/glass_general.h	Fri Oct 04 15:53:19 2013 +0400
@@ -45,14 +45,16 @@
             jmessage = (jstring)mainEnv->CallObjectMethod(throwable,
                     mainEnv->GetMethodID(mainEnv->FindClass("java/lang/Throwable"),
                     "getMessage", "()Ljava/lang/String;"));
-            message = mainEnv->GetStringUTFChars(jmessage, NULL);
+            message = jmessage == NULL ? "" : mainEnv->GetStringUTFChars(jmessage, NULL);
     }
     const char *what() const throw()
     {
         return message;
     }
     ~jni_exception() throw(){
-        mainEnv->ReleaseStringUTFChars(jmessage, message);
+        if (jmessage && message) {
+            mainEnv->ReleaseStringUTFChars(jmessage, message);
+        }
     }
 private:
     jthrowable throwable;
--- a/modules/graphics/src/main/native-glass/gtk/glass_screen.cpp	Fri Oct 04 10:53:17 2013 +0200
+++ b/modules/graphics/src/main/native-glass/gtk/glass_screen.cpp	Fri Oct 04 15:53:19 2013 +0400
@@ -140,7 +140,11 @@
 
 jobject createJavaScreen(JNIEnv* env, gint monitor_idx) {
     GdkScreen *default_gdk_screen = gdk_screen_get_default();
-    return createJavaScreen(env, default_gdk_screen, monitor_idx);
+    try {
+        return createJavaScreen(env, default_gdk_screen, monitor_idx);
+    } catch (jni_exception&) {
+        return NULL;
+    }
 }
 
 jobjectArray rebuild_screens(JNIEnv* env) {