提交 5be5839a 编写于 作者: I igerasim

8207750: Native handle leak in java.io.WinNTFileSystem.list()

Reviewed-by: bpb
上级 b589983a
...@@ -626,6 +626,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) ...@@ -626,6 +626,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
jstring name; jstring name;
jclass str_class; jclass str_class;
WCHAR *pathbuf; WCHAR *pathbuf;
DWORD err;
str_class = JNU_ClassString(env); str_class = JNU_ClassString(env);
CHECK_NULL_RETURN(str_class, NULL); CHECK_NULL_RETURN(str_class, NULL);
...@@ -687,8 +688,10 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) ...@@ -687,8 +688,10 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
len = 0; len = 0;
maxlen = 16; maxlen = 16;
rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL); rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
if (rv == NULL) // Couldn't allocate an array if (rv == NULL) { // Couldn't allocate an array
FindClose(handle);
return NULL; return NULL;
}
/* Scan the directory */ /* Scan the directory */
do { do {
if (!wcscmp(find_data.cFileName, L".") if (!wcscmp(find_data.cFileName, L".")
...@@ -696,13 +699,17 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) ...@@ -696,13 +699,17 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
continue; continue;
name = (*env)->NewString(env, find_data.cFileName, name = (*env)->NewString(env, find_data.cFileName,
(jsize)wcslen(find_data.cFileName)); (jsize)wcslen(find_data.cFileName));
if (name == NULL) if (name == NULL) {
return NULL; // error; FindClose(handle);
return NULL; // error
}
if (len == maxlen) { if (len == maxlen) {
old = rv; old = rv;
rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL); rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
if (rv == NULL || JNU_CopyObjectArray(env, rv, old, len) < 0) if (rv == NULL || JNU_CopyObjectArray(env, rv, old, len) < 0) {
FindClose(handle);
return NULL; // error return NULL; // error
}
(*env)->DeleteLocalRef(env, old); (*env)->DeleteLocalRef(env, old);
} }
(*env)->SetObjectArrayElement(env, rv, len++, name); (*env)->SetObjectArrayElement(env, rv, len++, name);
...@@ -710,9 +717,11 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) ...@@ -710,9 +717,11 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
} while (FindNextFileW(handle, &find_data)); } while (FindNextFileW(handle, &find_data));
if (GetLastError() != ERROR_NO_MORE_FILES) err = GetLastError();
return NULL; // error
FindClose(handle); FindClose(handle);
if (err != ERROR_NO_MORE_FILES) {
return NULL; // error
}
/* Copy the final results into an appropriately-sized array */ /* Copy the final results into an appropriately-sized array */
old = rv; old = rv;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册