diff options
author | Jan Schmidt <thaytan@mad.scientist.com> | 2006-02-18 22:41:31 +0000 |
---|---|---|
committer | Jan Schmidt <thaytan@mad.scientist.com> | 2006-02-18 22:41:31 +0000 |
commit | c8ddff9120ca0b4d906c1bfd491adbba4fd6d269 (patch) | |
tree | ac3b2f4b17bdde81d704fbf392bc770a27fe89ce /sys | |
parent | 0f1a1598ca6b1b4e5515be20e7ac92cb94b55702 (diff) |
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.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/ximage/ximagesink.c | 18 | ||||
-rw-r--r-- | sys/xvimage/xvimagesink.c | 18 |
2 files changed, 28 insertions, 8 deletions
diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index e62d599a..cc2fbddc 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 babfeca1..e160b118 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; |