changeset 5395:f7d9ab7563b5

7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c Summary: Free the memory in the error handling code. Reviewed-by: prr, jgodinez, bae
author zhouyx
date Mon, 12 Mar 2012 13:30:16 +0800
parents 79e27dae2596
children e20b5961ca5b
files src/solaris/native/sun/java2d/x11/X11SurfaceData.c
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Wed Oct 31 14:07:29 2012 +0000
+++ b/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Mon Mar 12 13:30:16 2012 +0800
@@ -563,6 +563,8 @@
         J2dRlsTraceLn1(J2D_TRACE_ERROR,
                        "X11SD_SetupSharedSegment shmget has failed: %s",
                        strerror(errno));
+        free((void *)shminfo);
+        XDestroyImage(img);
         return NULL;
     }
 
@@ -572,6 +574,8 @@
         J2dRlsTraceLn1(J2D_TRACE_ERROR,
                        "X11SD_SetupSharedSegment shmat has failed: %s",
                        strerror(errno));
+        free((void *)shminfo);
+        XDestroyImage(img);
         return NULL;
     }
 
@@ -592,6 +596,9 @@
         J2dRlsTraceLn1(J2D_TRACE_ERROR,
                        "X11SD_SetupSharedSegment XShmAttach has failed: %s",
                        strerror(errno));
+        shmdt(shminfo->shmaddr);
+        free((void *)shminfo);
+        XDestroyImage(img);
         return NULL;
     }
 
@@ -1485,13 +1492,10 @@
 #ifdef MITSHM
         if (image->obdata != NULL) {
             X11SD_DropSharedSegment((XShmSegmentInfo*)image->obdata);
-        } else {
-            free(image->data);
+            image->obdata = NULL;
         }
-#else
-        free(image->data);
 #endif /* MITSHM */
-        XFree(image);
+        XDestroyImage(image);
     }
 }