8207753: Handle to process snapshot is leaked if Process32First() fails
Reviewed-by: rriggs
--- a/src/java.base/windows/native/libjava/ProcessHandleImpl_win.c Thu Jul 19 12:55:24 2018 -0700
+++ b/src/java.base/windows/native/libjava/ProcessHandleImpl_win.c Thu Jul 19 13:41:26 2018 -0700
@@ -198,7 +198,7 @@
} else {
JNU_ThrowByName(env,
"java/lang/RuntimeException", "snapshot not available");
- return -1;
+ ppid = (DWORD)-1;
}
CloseHandle(hProcessSnap); // Ignore return code
return (jlong)ppid;
@@ -267,13 +267,13 @@
break;
}
if (jparentArray != NULL) {
- ppids = (*env)->GetLongArrayElements(env, jparentArray, NULL);
+ ppids = (*env)->GetLongArrayElements(env, jparentArray, NULL);
if (ppids == NULL) {
break;
}
}
if (jstimesArray != NULL) {
- stimes = (*env)->GetLongArrayElements(env, jstimesArray, NULL);
+ stimes = (*env)->GetLongArrayElements(env, jstimesArray, NULL);
if (stimes == NULL) {
break;
}
@@ -315,7 +315,7 @@
} else {
JNU_ThrowByName(env,
"java/lang/RuntimeException", "snapshot not available");
- return 0;
+ count = 0;
}
CloseHandle(hProcessSnap);
// If more pids than array had size for; count will be greater than array size