sys/: Set shared memory segments to be deleted as soon as we have attached, that way they get cleaned up automaticall...

Original commit message from CVS:
* 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.
This commit is contained in:
Jan Schmidt 2006-02-18 22:41:31 +00:00
parent 0f1a1598ca
commit c8ddff9120
3 changed files with 37 additions and 8 deletions

View file

@ -1,3 +1,12 @@
2006-02-18 Jan Schmidt <thaytan@mad.scientist.com>
* 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 <julien@moutte.net>
* ext/pango/gstclockoverlay.c: (gst_clock_overlay_get_text):

View file

@ -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);

View file

@ -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;