Skip to content

Commit 3cc8ce6

Browse files
tetrominocopybara-github
authored andcommitted
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. PiperOrigin-RevId: 355641836
1 parent 6cb8385 commit 3cc8ce6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/native/unix_jni.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,11 @@ static jbyteArray getxattr_common(JNIEnv *env,
10151015
}
10161016
} else {
10171017
result = env->NewByteArray(size);
1018-
env->SetByteArrayRegion(result, 0, size, value);
1018+
// Result may be NULL if allocation failed. In that case, we'll return the
1019+
// NULL and an OOME will be thrown when we are back in Java.
1020+
if (result != NULL) {
1021+
env->SetByteArrayRegion(result, 0, size, value);
1022+
}
10191023
}
10201024
ReleaseStringLatin1Chars(path_chars);
10211025
ReleaseStringLatin1Chars(name_chars);

0 commit comments

Comments
 (0)