8207753: Handle to process snapshot is leaked if Process32First() fails
authorigerasim
Thu, 19 Jul 2018 13:41:26 -0700
changeset 51171 c3a089b16cc9
parent 51170 7410cb248bbf
child 51172 e443c637b238
8207753: Handle to process snapshot is leaked if Process32First() fails Reviewed-by: rriggs
src/java.base/windows/native/libjava/ProcessHandleImpl_win.c
--- 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