Skip to content

Commit

Permalink
Propagate OOME if NewByteArray allocation failed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tetromino authored and larsrc-google committed Jul 30, 2021
1 parent bdbdc10 commit 706e3d6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/native/unix_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,11 @@ static jbyteArray getxattr_common(JNIEnv *env,
}
} else {
result = env->NewByteArray(size);
env->SetByteArrayRegion(result, 0, size, value);
// 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);
Expand Down

0 comments on commit 706e3d6

Please sign in to comment.