diff --git a/ChangeLog b/ChangeLog index f0596b9006..3528f80058 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-02-18 Jan Schmidt + + * sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls), + (gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy): + * sys/xvimage/xvimagesink.c: (gst_xvimage_buffer_destroy), + (gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new): + Set shared memory segments to be deleted as soon as we have attached, + that way they get cleaned up automatically if we crash. + 2006-02-18 Julien MOUTTE * ext/pango/gstclockoverlay.c: (gst_clock_overlay_get_text): diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index e62d599a98..cc2fbddca2 100644 --- a/sys/ximage/ximagesink.c +++ b/sys/ximage/ximagesink.c @@ -342,9 +342,16 @@ gst_ximagesink_check_xshm_calls (GstXImageSink * ximagesink, SHMInfo.shmaddr = shmat (SHMInfo.shmid, 0, 0); if (SHMInfo.shmaddr == ((void *) -1)) { GST_WARNING ("Failed to shmat: %s", g_strerror (errno)); + /* Clean up shm seg */ + shmctl (SHMInfo.shmid, IPC_RMID, 0); goto beach; } + /* Delete the shared memory segment as soon as we manage to attach. + * This way, it will be deleted as soon as we detach later, and not + * leaked if we crash. */ + shmctl (SHMInfo.shmid, IPC_RMID, 0); + ximage->data = SHMInfo.shmaddr; SHMInfo.readOnly = FALSE; @@ -374,8 +381,6 @@ beach: } if (SHMInfo.shmaddr != ((void *) -1)) shmdt (SHMInfo.shmaddr); - if (SHMInfo.shmid > 0) - shmctl (SHMInfo.shmid, IPC_RMID, 0); if (ximage) XDestroyImage (ximage); return result; @@ -435,9 +440,16 @@ gst_ximagesink_ximage_new (GstXImageSink * ximagesink, GstCaps * caps) if (ximage->SHMInfo.shmaddr == ((void *) -1)) { GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE, (NULL), ("Failed to shmat: %s", g_strerror (errno))); + /* Clean up the shared memory segment */ + shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0); goto beach; } + /* Now that we've attached, we can delete the shared memory segment. + * This way, it will be deleted as soon as we detach later, and not + * leaked if we crash. */ + shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0); + ximage->ximage->data = ximage->SHMInfo.shmaddr; ximage->SHMInfo.readOnly = FALSE; @@ -514,8 +526,6 @@ gst_ximagesink_ximage_destroy (GstXImageSink * ximagesink, XSync (ximagesink->xcontext->disp, 0); shmdt (ximage->SHMInfo.shmaddr); } - if (ximage->SHMInfo.shmid > 0) - shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0); if (ximage->ximage) XDestroyImage (ximage->ximage); diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index babfeca1e3..e160b1180f 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -237,8 +237,6 @@ gst_xvimage_buffer_destroy (GstXvImageBuffer * xvimage) XSync (xvimagesink->xcontext->disp, FALSE); shmdt (xvimage->SHMInfo.shmaddr); } - if (xvimage->SHMInfo.shmid > 0) - shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0); if (xvimage->xvimage) XFree (xvimage->xvimage); } else @@ -419,9 +417,16 @@ gst_xvimagesink_check_xshm_calls (GstXContext * xcontext) SHMInfo.shmaddr = shmat (SHMInfo.shmid, 0, 0); if (SHMInfo.shmaddr == ((void *) -1)) { GST_WARNING ("Failed to shmat: %s", g_strerror (errno)); + /* Clean up the shared memory segment */ + shmctl (SHMInfo.shmid, IPC_RMID, 0); goto beach; } + /* Delete the shared memory segment as soon as we manage to attach. + * This way, it will be deleted as soon as we detach later, and not + * leaked if we crash. */ + shmctl (SHMInfo.shmid, IPC_RMID, 0); + xvimage->data = SHMInfo.shmaddr; SHMInfo.readOnly = FALSE; @@ -452,8 +457,6 @@ beach: } if (SHMInfo.shmaddr != ((void *) -1)) shmdt (SHMInfo.shmaddr); - if (SHMInfo.shmid > 0) - shmctl (SHMInfo.shmid, IPC_RMID, 0); if (xvimage) XFree (xvimage); return result; @@ -521,9 +524,16 @@ gst_xvimagesink_xvimage_new (GstXvImageSink * xvimagesink, GstCaps * caps) if (xvimage->SHMInfo.shmaddr == ((void *) -1)) { GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE, (NULL), ("Failed to shmat: %s", g_strerror (errno))); + /* Clean up the shared memory segment */ + shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0); goto beach; } + /* Delete the shared memory segment as soon as we manage to attach. + * This way, it will be deleted as soon as we detach later, and not + * leaked if we crash. */ + shmctl (xvimage->SHMInfo.shmid, IPC_RMID, 0); + xvimage->xvimage->data = xvimage->SHMInfo.shmaddr; xvimage->SHMInfo.readOnly = FALSE;