[RFC] glx: fix DRI2 memory leak

Jesse Barnes jbarnes at virtuousgeek.org
Wed Mar 25 10:21:51 PDT 2009

In trying to track down the memory leak in 20704, I found that the DRI2
drawable destroy routine doesn't seem to get called when new drawables
are created and old ones destroyed (as in the glViewport case in the

The GLX core code takes care of destroying drawables correctly though,
and even calls DestroyPixmap at the right time.  However, DRI2
drawables have more state associated with them than just a single
pixmap, so we have a __glXDRIdrawableDestroy function that takes care
of that.  However, by the time we get there, the GLX drawable is gone,
so I never saw the
    if (drawable->pDraw != NULL)
case get triggered...

The simple patch below fixed that, but apparently isn't correct (see
the bug report) since it causes crashes after a time.  My patch was
missing another change to set the private->count correctly in
dri2GetBuffers though, which may be part of the fix as well.

Has anyone else seen this leak?  Anyone care to educate me a bit more
about GLX drawable lifetime rules?


diff --git a/glx/glxext.c b/glx/glxext.c
index c882372..73e5a9b 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -127,9 +127,9 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
-    glxPriv->pDraw = NULL;
     glxPriv->drawId = 0;
+    glxPriv->pDraw = NULL;
     return True;

More information about the xorg mailing list