changeset 22961:37d77143ce29

8034102: Check solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c for JNI pending exceptions Reviewed-by: chegar, henryjen
author alanb
date Wed, 12 Feb 2014 17:51:31 +0000
parents 436141944957
children 309eaab8c853
files jdk/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c	Wed Feb 12 14:23:52 2014 +0000
+++ b/jdk/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c	Wed Feb 12 17:51:31 2014 +0000
@@ -39,12 +39,15 @@
                                                      jint form)
 {
     jcharArray result = NULL;
-    char chars_buf[(PATH_MAX + 1) * 2];     // utf16 + zero padding
+    char *chars;
     CFMutableStringRef csref = CFStringCreateMutable(NULL, 0);
     if (csref == NULL) {
         JNU_ThrowOutOfMemoryError(env, "native heap");
-    } else {
-        char *chars = (char*)(*env)->GetPrimitiveArrayCritical(env, path, 0);
+        return NULL;
+    }
+    chars = (char*)(*env)->GetPrimitiveArrayCritical(env, path, 0);
+    if (chars != NULL) {
+        char chars_buf[(PATH_MAX + 1) * 2];     // utf16 + zero padding
         jsize len = (*env)->GetArrayLength(env, path);
         CFStringAppendCharacters(csref, (const UniChar*)chars, len);
         (*env)->ReleasePrimitiveArrayCritical(env, path, chars, 0);
@@ -53,24 +56,26 @@
         if (len < PATH_MAX) {
             if (CFStringGetCString(csref, chars_buf, sizeof(chars_buf), kCFStringEncodingUTF16)) {
                 result = (*env)->NewCharArray(env, len);
-                (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)&chars_buf);
+                if (result != NULL) {
+                    (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)&chars_buf);
+                }
             }
         } else {
             int ulen = (len + 1) * 2;
             chars = malloc(ulen);
             if (chars == NULL) {
-                CFRelease(csref);
                 JNU_ThrowOutOfMemoryError(env, "native heap");
-                return result;
             } else {
                 if (CFStringGetCString(csref, chars, ulen, kCFStringEncodingUTF16)) {
                     result = (*env)->NewCharArray(env, len);
-                    (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)chars);
+                    if (result != NULL) {
+                        (*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)chars);
+                    }
                 }
                 free(chars);
             }
         }
-        CFRelease(csref);
     }
+    CFRelease(csref);
     return result;
 }