Save errno in unix_jni.cc stat when throwing exceptions.
It's otherwise possible that we do other syscalls in between the original syscall and us reading the errno for use in the exception.
PiperOrigin-RevId: 181367811
diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc
index bf72dce..7615c67 100644
--- a/src/main/native/unix_jni.cc
+++ b/src/main/native/unix_jni.cc
@@ -399,11 +399,11 @@
// ENAMETOOLONGEFAULT -> RuntimeException
// ENOMEM -> OutOfMemoryError
- if (PostRuntimeException(env, errno, path_chars)) {
+ if (PostRuntimeException(env, saved_errno, path_chars)) {
::ReleaseStringLatin1Chars(path_chars);
return NULL;
} else if (should_throw) {
- ::PostFileException(env, errno, path_chars);
+ ::PostFileException(env, saved_errno, path_chars);
::ReleaseStringLatin1Chars(path_chars);
return NULL;
}