RFR [XS] : 8213366: (fs) avoid handle leak in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0
Chris Hegarty
chris.hegarty at oracle.com
Mon Nov 5 13:58:36 UTC 2018
On 05/11/18 12:45, Baesken, Matthias wrote:
> Btw when looking around a bit in WindowsNativeDispatcher.c , I found a similar issue in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0;
> See the coding below .
>
> FindFirstStreamW as well suggests a FindClose on the returned handle after it is not needed any longer.
> See
>
> https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirststreamw
>
> However the early return after jstring name = (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));
> Misses this :
>
> JNIEXPORT void JNICALL
> Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0(JNIEnv* env, jclass this,
> jlong address, jobject obj)
> {
> WIN32_FIND_STREAM_DATA data;
> LPCWSTR lpFileName = jlong_to_ptr(address);
> HANDLE handle;
>
> 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)
> return;
> (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));
> (*env)->SetObjectField(env, obj, findStream_name, name);
> } else {
> ......
> }
>
>
> Should I open another bug or add this to 8213366 in another webrev ?
It makes sense to add it to 8213366.
-Chris.
More information about the nio-dev
mailing list