8207753: Handle to process snapshot is leaked if Process32First() fails

Reviewed-by: rriggs
This commit is contained in:
Ivan Gerasimov 2018-07-19 13:41:26 -07:00
parent 5226a6a2bb
commit 121c59eb6d

View file

@ -198,7 +198,7 @@ Java_java_lang_ProcessHandleImpl_parent0(JNIEnv *env,
} else { } else {
JNU_ThrowByName(env, JNU_ThrowByName(env,
"java/lang/RuntimeException", "snapshot not available"); "java/lang/RuntimeException", "snapshot not available");
return -1; ppid = (DWORD)-1;
} }
CloseHandle(hProcessSnap); // Ignore return code CloseHandle(hProcessSnap); // Ignore return code
return (jlong)ppid; return (jlong)ppid;
@ -267,13 +267,13 @@ Java_java_lang_ProcessHandleImpl_getProcessPids0(JNIEnv *env,
break; break;
} }
if (jparentArray != NULL) { if (jparentArray != NULL) {
ppids = (*env)->GetLongArrayElements(env, jparentArray, NULL); ppids = (*env)->GetLongArrayElements(env, jparentArray, NULL);
if (ppids == NULL) { if (ppids == NULL) {
break; break;
} }
} }
if (jstimesArray != NULL) { if (jstimesArray != NULL) {
stimes = (*env)->GetLongArrayElements(env, jstimesArray, NULL); stimes = (*env)->GetLongArrayElements(env, jstimesArray, NULL);
if (stimes == NULL) { if (stimes == NULL) {
break; break;
} }
@ -315,7 +315,7 @@ Java_java_lang_ProcessHandleImpl_getProcessPids0(JNIEnv *env,
} else { } else {
JNU_ThrowByName(env, JNU_ThrowByName(env,
"java/lang/RuntimeException", "snapshot not available"); "java/lang/RuntimeException", "snapshot not available");
return 0; count = 0;
} }
CloseHandle(hProcessSnap); CloseHandle(hProcessSnap);
// If more pids than array had size for; count will be greater than array size // If more pids than array had size for; count will be greater than array size