# HG changeset patch # User mbaesken # Date 1541578417 -3600 # Node ID b43f8976cf81c4eb7cde5823e4567a2232f1e360 # Parent b0af758a092cdf44ebc275c28e4737fc769a3a9f 8213366: (fs) avoid handle leak in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0 Reviewed-by: alanb, chegar diff -r b0af758a092c -r b43f8976cf81 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 {