8080225: FileInput/OutputStream/FileChannel cleanup should be improved

Reviewed-by: mchung, plevart, bpb
This commit is contained in:
Roger Riggs 2017-12-01 16:40:08 -05:00
parent b93586c51e
commit f29e21abb1
23 changed files with 1104 additions and 261 deletions

View file

@ -71,8 +71,17 @@ Java_java_io_FileDescriptor_getAppend(JNIEnv *env, jclass fdClass, jint fd) {
return ((flags & O_APPEND) == 0) ? JNI_FALSE : JNI_TRUE;
}
JNIEXPORT void JNICALL
Java_java_io_FileDescriptor_cleanupClose0(JNIEnv *env, jclass fdClass, jint fd) {
if (fd != -1) {
if (close(fd) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "close failed");
}
}
}
// instance method close0 for FileDescriptor
JNIEXPORT void JNICALL
Java_java_io_FileDescriptor_close(JNIEnv *env, jobject this) {
Java_java_io_FileDescriptor_close0(JNIEnv *env, jobject this) {
fileDescriptorClose(env, this);
}

View file

@ -139,6 +139,11 @@ fileDescriptorClose(JNIEnv *env, jobject this)
if ((*env)->ExceptionOccurred(env)) {
return;
}
if (fd == -1) {
return; // already closed and set to -1
}
/* Set the fd to -1 before closing it so that the timing window
* of other threads using the wrong fd (closed but recycled fd,
* that gets re-opened with some other filename) is reduced.