7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
authorlittlee
Mon, 12 Mar 2012 13:30:16 +0800
changeset 12170 bdd7741e16de
parent 12021 e070119aa56e
child 12171 ab7bb1fd211f
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 Contributed-by: Sean Chou <zhouyx@linux.vnet.ibm.com>
jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
--- a/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Wed Jul 05 18:04:46 2017 +0200
+++ b/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Mon Mar 12 13:30:16 2012 +0800
@@ -540,6 +540,8 @@
         J2dRlsTraceLn1(J2D_TRACE_ERROR,
                        "X11SD_SetupSharedSegment shmget has failed: %s",
                        strerror(errno));
+        free((void *)shminfo);
+        XDestroyImage(img);
         return NULL;
     }
 
@@ -549,6 +551,8 @@
         J2dRlsTraceLn1(J2D_TRACE_ERROR,
                        "X11SD_SetupSharedSegment shmat has failed: %s",
                        strerror(errno));
+        free((void *)shminfo);
+        XDestroyImage(img);
         return NULL;
     }
 
@@ -569,6 +573,9 @@
         J2dRlsTraceLn1(J2D_TRACE_ERROR,
                        "X11SD_SetupSharedSegment XShmAttach has failed: %s",
                        strerror(errno));
+        shmdt(shminfo->shmaddr);
+        free((void *)shminfo);
+        XDestroyImage(img);
         return NULL;
     }
 
@@ -1344,13 +1351,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);
     }
 }