diff --git a/src/java.base/share/native/libjava/ClassLoader.c b/src/java.base/share/native/libjava/ClassLoader.c index bbdff87b0b3..da34a7b438b 100644 --- a/src/java.base/share/native/libjava/ClassLoader.c +++ b/src/java.base/share/native/libjava/ClassLoader.c @@ -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;