8283225: ClassLoader.c produces incorrect OutOfMemory Exception when length is 0 (aix)

Reviewed-by: stuefe, rriggs, dholmes
This commit is contained in:
Tyler Steele 2022-03-18 07:02:26 +00:00 committed by Thomas Stuefe
parent d83cee98b5
commit cab4ff6454

View File

@ -99,7 +99,12 @@ Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
return 0;
}
// On AIX malloc(0) returns NULL which looks like an out-of-memory condition; so adjust it to malloc(1)
#ifdef _AIX
body = (jbyte *)malloc(length == 0 ? 1 : length);
#else
body = (jbyte *)malloc(length);
#endif
if (body == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
@ -239,7 +244,13 @@ Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
return 0;
}
// On AIX malloc(0) returns NULL which looks like an out-of-memory condition; so adjust it to malloc(1)
#ifdef _AIX
body = (jbyte *)malloc(length == 0 ? 1 : length);
#else
body = (jbyte *)malloc(length);
#endif
if (body == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
return 0;