changeset 52454:b43f8976cf81

8213366: (fs) avoid handle leak in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0 Reviewed-by: alanb, chegar
author mbaesken
date Wed, 07 Nov 2018 09:13:37 +0100
parents b0af758a092c
children a0ea20bc7af0
files src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Tue Nov 06 16:04:50 2018 -0800
+++ b/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Wed Nov 07 09:13:37 2018 +0100
@@ -311,8 +311,10 @@
     HANDLE handle = FindFirstFileW(lpFileName, &data);
     if (handle != INVALID_HANDLE_VALUE) {
         jstring name = (*env)->NewString(env, data.cFileName, (jsize)wcslen(data.cFileName));
-        if (name == NULL)
+        if (name == NULL) {
+            FindClose(handle);
             return;
+        }
         (*env)->SetLongField(env, obj, findFirst_handle, ptr_to_jlong(handle));
         (*env)->SetObjectField(env, obj, findFirst_name, name);
         (*env)->SetIntField(env, obj, findFirst_attributes, data.dwFileAttributes);
@@ -362,8 +364,10 @@
     handle = FindFirstStreamW(lpFileName, FindStreamInfoStandard, &data, 0);
     if (handle != INVALID_HANDLE_VALUE) {
         jstring name = (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));
-        if (name == NULL)
+        if (name == NULL) {
+            FindClose(handle);
             return;
+        }
         (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));
         (*env)->SetObjectField(env, obj, findStream_name, name);
     } else {