diff --git a/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c b/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c index f3602b8fdb78dc50e20c5b5e1bb153b495e7627f..5c752930c14cafbd43ec43ae47d4705a7cf08bab 100644 --- a/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c +++ b/src/solaris/native/sun/nio/fs/MacOSXNativeDispatcher.c @@ -39,12 +39,15 @@ Java_sun_nio_fs_MacOSXNativeDispatcher_normalizepath(JNIEnv* env, jclass this, 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 @@ Java_sun_nio_fs_MacOSXNativeDispatcher_normalizepath(JNIEnv* env, jclass this, 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; }