8005194: [parfait] #353 sun/awt/image/jpeg/imageioJPEG.c Memory leak of pointer 'scale' allocated with calloc()
authorjgodinez
Wed, 06 Feb 2013 14:45:02 -0800
changeset 15627 46054ae31dfc
parent 15504 c13b899e2b15
child 15628 228422512f97
8005194: [parfait] #353 sun/awt/image/jpeg/imageioJPEG.c Memory leak of pointer 'scale' allocated with calloc() Reviewed-by: prr, vadim Contributed-by: jia-hong.chen@oracle.com
jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c
--- a/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Mon Feb 04 12:04:38 2013 -0800
+++ b/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Wed Feb 06 14:45:02 2013 -0800
@@ -2694,6 +2694,11 @@
             scale[i] = (UINT8*) malloc((maxBandValue + 1) * sizeof(UINT8));
 
             if (scale[i] == NULL) {
+                // Cleanup before throwing an out of memory exception
+                for (j = 0; j < i; j++) {
+                    free(scale[j]);
+                }
+                free(scale);
                 JNU_ThrowByName( env, "java/lang/OutOfMemoryError",
                                  "Writing JPEG Stream");
                 return JNI_FALSE;