提交 5fc3c6db 编写于 作者: I igerasim

8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

Reviewed-by: martin, alanb
上级 85b14a0c
...@@ -315,7 +315,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) { ...@@ -315,7 +315,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) {
int res = -1; int res = -1;
RESTARTABLE(dup((int)fd), res); RESTARTABLE(dup((int)fd), res);
if (fd == -1) { if (res == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} }
return (jint)res; return (jint)res;
...@@ -343,13 +343,14 @@ Java_sun_nio_fs_UnixNativeDispatcher_fopen0(JNIEnv* env, jclass this, ...@@ -343,13 +343,14 @@ Java_sun_nio_fs_UnixNativeDispatcher_fopen0(JNIEnv* env, jclass this,
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream) Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream)
{ {
int res;
FILE* fp = jlong_to_ptr(stream); FILE* fp = jlong_to_ptr(stream);
do { /* NOTE: fclose() wrapper is only used with read-only streams.
res = fclose(fp); * If it ever is used with write streams, it might be better to add
} while (res == EOF && errno == EINTR); * RESTARTABLE(fflush(fp)) before closing, to make sure the stream
if (res == EOF) { * is completely written even if fclose() failed.
*/
if (fclose(fp) == EOF && errno != EINTR) {
throwUnixException(env, errno); throwUnixException(env, errno);
} }
} }
...@@ -657,11 +658,9 @@ Java_sun_nio_fs_UnixNativeDispatcher_fdopendir(JNIEnv* env, jclass this, int dfd ...@@ -657,11 +658,9 @@ Java_sun_nio_fs_UnixNativeDispatcher_fdopendir(JNIEnv* env, jclass this, int dfd
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) { Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) {
int err;
DIR* dirp = jlong_to_ptr(dir); DIR* dirp = jlong_to_ptr(dir);
RESTARTABLE(closedir(dirp), err); if (closedir(dirp) == -1 && errno != EINTR) {
if (errno == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册