8004344: Fix a crash in ToolkitErrorHandler() in XlibWrapper.c
authoraph
Tue, 04 Dec 2012 14:02:08 +0000
changeset 14659 cda39b3e7f15
parent 14658 67661687f722
child 14660 7fc763673645
child 14753 a56a685d137f
8004344: Fix a crash in ToolkitErrorHandler() in XlibWrapper.c Summary: Code does not check for JNU_GetEnv returning NULL. Reviewed-by: anthony
jdk/src/solaris/native/sun/xawt/XlibWrapper.c
--- a/jdk/src/solaris/native/sun/xawt/XlibWrapper.c	Tue Dec 04 17:17:45 2012 +0400
+++ b/jdk/src/solaris/native/sun/xawt/XlibWrapper.c	Tue Dec 04 14:02:08 2012 +0000
@@ -1260,13 +1260,15 @@
 
 JavaVM* jvm = NULL;
 static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) {
+    JNIEnv * env;
     if (jvm != NULL) {
-        JNIEnv * env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
-        return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", "globalErrorHandler", "(JJ)I",
-                                          ptr_to_jlong(dpy), ptr_to_jlong(event)).i;
-    } else {
-        return 0;
+        env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+        if (env) {
+            return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", "globalErrorHandler", "(JJ)I",
+                                              ptr_to_jlong(dpy), ptr_to_jlong(event)).i;
+        }
     }
+    return 0;
 }
 
 /*