glx: Fix use after free problem
authorKristian Høgsberg <krh@bitplanet.net>
Wed, 8 Sep 2010 18:51:18 +0000 (14:51 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 8 Sep 2010 22:54:48 +0000 (18:54 -0400)
src/glx/glxcurrent.c

index 710985b02c1a696bea14d27bb5a7e6c14a4e0661..0d359f72b4adb6aca0519abe7ccd49bb53d77b44 100644 (file)
@@ -248,12 +248,6 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
       oldGC->currentDrawable = None;
       oldGC->currentReadable = None;
       oldGC->thread_id = 0;
-      if (oldGC->xid == None && oldGC != gc)
-        /* We are switching away from a context that was
-         * previously destroyed, so we need to free the memory
-         * for the old handle.
-         */
-        oldGC->vtable->destroy(oldGC);
    }
 
    if (gc) {
@@ -267,6 +261,13 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
       __glXSetCurrentContextNull();
    }
 
+   if (oldGC != &dummyContext && oldGC->xid == None && oldGC != gc) {
+      /* We are switching away from a context that was
+       * previously destroyed, so we need to free the memory
+       * for the old handle. */
+      oldGC->vtable->destroy(oldGC);
+   }
+
    if (ret) {
       __glXGenerateError(dpy, gc, None, ret, X_GLXMakeContextCurrent);
       return GL_FALSE;