8213366: (fs) avoid handle leak in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0
authormbaesken
Wed, 07 Nov 2018 09:13:37 +0100
changeset 52432 b43f8976cf81
parent 52431 b0af758a092c
child 52433 a0ea20bc7af0
8213366: (fs) avoid handle leak in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0 Reviewed-by: alanb, chegar
src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
--- 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 {