sys/: Fix a possible SHM leak if we crash. All other apps using XShm are doing that.
authorJulien Moutte <julien@moutte.net>
Tue, 17 Feb 2004 11:06:52 +0000 (11:06 +0000)
committerJulien Moutte <julien@moutte.net>
Tue, 17 Feb 2004 11:06:52 +0000 (11:06 +0000)
Original commit message from CVS:
2004-02-17  Julien MOUTTE <julien@moutte.net>

* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xvimage_new): Fix a
possible SHM leak if we crash. All other apps using XShm are doing
that.

ChangeLog
sys/ximage/ximagesink.c
sys/xvimage/xvimagesink.c

index 8c571fc..492666a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-02-17  Julien MOUTTE <julien@moutte.net>
+
+       * sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new):
+       * sys/xvimage/xvimagesink.c: (gst_xvimagesink_xvimage_new): Fix a
+       possible SHM leak if we crash. All other apps using XShm are doing
+       that.
+
 2004-02-17  Julien MOUTTE  <julien@moutte.net>
 
        * sys/ximage/ximagesink.c: (gst_ximagesink_renegotiate_size),
index d727185..4f61ae6 100644 (file)
@@ -178,6 +178,11 @@ gst_ximagesink_ximage_new (GstXImageSink *ximagesink, gint width, gint height)
       ximage->SHMInfo.readOnly = FALSE;
   
       XShmAttach (ximagesink->xcontext->disp, &ximage->SHMInfo);
+      
+      XSync (ximagesink->xcontext->disp, FALSE);
+      
+      shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0);
+      ximage->SHMInfo.shmid = -1;
     }
   else
 #endif /* HAVE_XSHM */
@@ -191,13 +196,11 @@ gst_ximagesink_ximage_new (GstXImageSink *ximagesink, gint width, gint height)
                                      ximage->width, ximage->height,
                                      ximagesink->xcontext->bpp,
                                      ximage->width * (ximagesink->xcontext->bpp / 8));
-    }
-  
-  if (ximage->ximage)
-    {
+      
       XSync (ximagesink->xcontext->disp, FALSE);
     }
-  else
+  
+  if (!ximage->ximage)
     {
       if (ximage->data)
         g_free (ximage->data);
index c817a8e..fb0fd2f 100644 (file)
@@ -191,6 +191,11 @@ gst_xvimagesink_xvimage_new (GstXvImageSink *xvimagesink,
       xvimage->SHMInfo.readOnly = FALSE;
   
       XShmAttach (xvimagesink->xcontext->disp, &xvimage->SHMInfo);
+      
+      XSync (xvimagesink->xcontext->disp, FALSE);
+      
+      shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0);
+      xvimage->SHMInfo.shmid = -1;
     }
   else
 #endif /* HAVE_XSHM */
@@ -202,13 +207,11 @@ gst_xvimagesink_xvimage_new (GstXvImageSink *xvimagesink,
                                         xvimage->width, xvimage->height);
       
       xvimage->data = g_malloc (xvimage->xvimage->data_size);
-    }
-
-  if (xvimage->xvimage)
-    {
+      
       XSync (xvimagesink->xcontext->disp, FALSE);
     }
-  else
+
+  if (!xvimage->xvimage)
     {
       if (xvimage->data)
         g_free (xvimage->data);