The implementation of exitValue() is not careful enough to check for errors.
JNIEXPORT jint JNICALL
Java_java_lang_ProcessImpl_exitValue(JNIEnv *env, jobject process)
{
jint exit_code;
jboolean exc;
jlong handle = JNU_GetFieldByName(env, &exc, process, "handle", "J").j;
if (exc) {
return 0;
}
GetExitCodeProcess((void *)handle, &exit_code);
if (exit_code == STILL_ACTIVE) {
JNU_ThrowByName(env, "java/lang/IllegalThreadStateException",
"process has not exited");
return -1;
}
return exit_code;
}
What happens if GetExitCodeProcess fails?
In this case there should be an exception thrown with a human-readable
error description.
Also, in this case exit_code may never be initialized, with the result that the
returned value is whatever random garbage was on the stack at the point of call.
JNIEXPORT jint JNICALL
Java_java_lang_ProcessImpl_exitValue(JNIEnv *env, jobject process)
{
jint exit_code;
jboolean exc;
jlong handle = JNU_GetFieldByName(env, &exc, process, "handle", "J").j;
if (exc) {
return 0;
}
GetExitCodeProcess((void *)handle, &exit_code);
if (exit_code == STILL_ACTIVE) {
JNU_ThrowByName(env, "java/lang/IllegalThreadStateException",
"process has not exited");
return -1;
}
return exit_code;
}
What happens if GetExitCodeProcess fails?
In this case there should be an exception thrown with a human-readable
error description.
Also, in this case exit_code may never be initialized, with the result that the
returned value is whatever random garbage was on the stack at the point of call.
- relates to
-
JDK-6315640 (process) Depleting native Win32 process handles when running on large Java heap
-
- Closed
-