RFR [XS] : 8213366: (fs) avoid handle leak in Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0
Baesken, Matthias
matthias.baesken at sap.com
Mon Nov 5 12:45:21 UTC 2018
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 ?
Best regards, Matthias
> -----Original Message-----
> From: Baesken, Matthias
> Sent: Montag, 5. November 2018 13:23
> To: 'Chris Hegarty' <chris.hegarty at oracle.com>; nio-dev at openjdk.java.net;
> Alan Bateman (Alan.Bateman at oracle.com) <Alan.Bateman at oracle.com>
> Subject: RE: RFR [XS] : 8213366: (fs) avoid handle leak in
> Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0
>
> Hi Chris / Alan, thanks for the reviews .
>
> Best regards, Matthias
>
>
> > -----Original Message-----
> > From: Chris Hegarty <chris.hegarty at oracle.com>
> > Sent: Montag, 5. November 2018 13:09
> > To: Baesken, Matthias <matthias.baesken at sap.com>; nio-
> > dev at openjdk.java.net
> > Subject: Re: RFR [XS] : 8213366: (fs) avoid handle leak in
> > Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0
> >
> >
> > On 05/11/18 11:44, Baesken, Matthias wrote:
> > > ...
> > >
> > > Bug/webrev :
> > >
> > > https://bugs.openjdk.java.net/browse/JDK-8213366
> > >
> > > http://cr.openjdk.java.net/~mbaesken/webrevs/8213366.0/webrev/
> >
> > Looks good.
> >
> > I added the `noreg-hard` label to the bug, since there is no
> > testcase ( which is reasonable for this issue ).
> >
> > -Chris.
More information about the nio-dev
mailing list