Propagate OOME if NewByteArray allocation failed
It's possible for NewByteArray to fail when the JVM is running out of memory. In
that case, we want to propagate the OOME to the caller instead of segfaulting in
the JVM.
RELNOTES: None.
@@ -1015,8 +1015,12 @@ static jbyteArray getxattr_common(JNIEnv *env,
}
} else {
result = env->NewByteArray(size);
+ // Result may be NULL if allocation failed. In that case, we'll return the
+ // NULL and an OOME will be thrown when we are back in Java.
+ if (result != NULL) {
env->SetByteArrayRegion(result, 0, size, value);
}
+ }
ReleaseStringLatin1Chars(path_chars);
ReleaseStringLatin1Chars(name_chars);
return result;
