[Mesa-dev] [PATCH] winsys/sw/xlib: Prevent shared memory segment leakage.

jfonseca at vmware.com jfonseca at vmware.com
Wed Apr 24 02:54:03 PDT 2013


From: José Fonseca <jfonseca at vmware.com>

Running piglit with this was causing all sort of weird stuff happening
to my desktop (Chromium webpages become blank, Qt Creator flickered,
etc).  I tracked this down to shared memory segment leakage when GL is
not shutdown properly. The segments can be seen running `ipcs` and
looking for nattch==0.

This changes fixes this by calling shmctl(IPC_RMID) soon after creation
(which does not remove the segment immediately, but simply marks it for
removal when no more processes are attached).

This matches src/mesa/drivers/x11/xm_buffer.c behaviour.

v2:
- move shmctl(IPC_RMID) after XShmAttach() for *BSD, per Chris Wilson
- remove stray debug printfs, spotted by Ian Romanick

NOTE: This is a candidate for stable branches.
---
 src/gallium/winsys/sw/xlib/xlib_sw_winsys.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
index 3aef8da..6e71530 100644
--- a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
+++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
@@ -165,6 +165,7 @@ alloc_shm_ximage(struct xlib_displaytarget *xlib_dt,
                                       &xlib_dt->shminfo,
                                       width, height);
    if (xlib_dt->tempImage == NULL) {
+      shmctl(xlib_dt->shminfo.shmid, IPC_RMID, 0);
       xlib_dt->shm = False;
       return;
    }
@@ -176,6 +177,11 @@ alloc_shm_ximage(struct xlib_displaytarget *xlib_dt,
    XShmAttach(xlib_dt->display, &xlib_dt->shminfo);
    XSync(xlib_dt->display, False);
 
+   /* Mark the segment to be destroyed, so that it is automatically destroyed
+    * when this process dies.  Needs to be after XShmAttach() for *BSD.
+    */
+   shmctl(xlib_dt->shminfo.shmid, IPC_RMID, 0);
+
    if (XErrorFlag) {
       /* we are on a remote display, this error is normal, don't print it */
       XFlush(xlib_dt->display);
-- 
1.7.10.4



More information about the mesa-dev mailing list