src/share/native/java/util/zip/Deflater.c

Print this page

        

@@ -135,18 +135,18 @@
         if ((*env)->GetBooleanField(env, this, setParamsID)) {
             int level = (*env)->GetIntField(env, this, levelID);
             int strategy = (*env)->GetIntField(env, this, strategyID);
 
             in_buf = (jbyte *) malloc(this_len);
-            if (in_buf == 0) {
+            if (in_buf == 0 && this_len > 0) {
                 JNU_ThrowOutOfMemoryError(env, 0);
                 return 0;
             }
             (*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
 
             out_buf = (jbyte *) malloc(len);
-            if (out_buf == 0) {
+            if (out_buf == 0 && len > 0) {
                 free(in_buf);
                 JNU_ThrowOutOfMemoryError(env, 0);
                 return 0;
             }
 

@@ -178,18 +178,18 @@
             }
         } else {
             jboolean finish = (*env)->GetBooleanField(env, this, finishID);
 
             in_buf = (jbyte *) malloc(this_len);
-            if (in_buf == 0) {
+            if (in_buf == 0 && this_len > 0) {
                 JNU_ThrowOutOfMemoryError(env, 0);
                 return 0;
             }
             (*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
 
             out_buf = (jbyte *) malloc(len);
-            if (out_buf == 0) {
+            if (out_buf == 0 && len > 0) {
                 free(in_buf);
                 JNU_ThrowOutOfMemoryError(env, 0);
                 return 0;
             }