ba9193
From ae982a27e4059fecd4048d245e6aa02f8dcc97d0 Mon Sep 17 00:00:00 2001
ba9193
From: Dave Airlie <airlied@redhat.com>
ba9193
Date: Thu, 24 Apr 2008 16:37:29 +1000
ba9193
Subject: [PATCH] glx: test for valid read and draw privates before using them
ba9193
ba9193
this should fix a bug where f-spot exiting blows up the X server
ba9193
---
ba9193
 GL/glx/glxutil.c |   58 +++++++++++++++++++++++++++--------------------------
ba9193
 1 files changed, 30 insertions(+), 28 deletions(-)
ba9193
ba9193
diff --git a/GL/glx/glxutil.c b/GL/glx/glxutil.c
ba9193
index 11e9f89..aa23a95 100644
ba9193
--- a/GL/glx/glxutil.c
ba9193
+++ b/GL/glx/glxutil.c
ba9193
@@ -81,38 +81,40 @@ __glXDeassociateContext(__GLXcontext *glxc)
ba9193
     __GLXcontext *curr, *prev;
ba9193
 
ba9193
     prev = NULL;
ba9193
-    for ( curr = glxc->drawPriv->drawGlxc
ba9193
-	  ; curr != NULL
ba9193
-	  ; prev = curr, curr = curr->nextDrawPriv ) {
ba9193
-	if (curr == glxc) {
ba9193
-	    /* found context.  Deassociate. */
ba9193
-	    if (prev == NULL) {
ba9193
-		glxc->drawPriv->drawGlxc = curr->nextDrawPriv;
ba9193
-	    } else {
ba9193
-		prev->nextDrawPriv = curr->nextDrawPriv;
ba9193
+    if (glxc->drawPriv) {
ba9193
+        for ( curr = glxc->drawPriv->drawGlxc; curr != NULL
ba9193
+	      ; prev = curr, curr = curr->nextDrawPriv ) {
ba9193
+	    if (curr == glxc) {
ba9193
+	        /* found context.  Deassociate. */
ba9193
+	        if (prev == NULL) {
ba9193
+		    glxc->drawPriv->drawGlxc = curr->nextDrawPriv;
ba9193
+	        } else {
ba9193
+		    prev->nextDrawPriv = curr->nextDrawPriv;
ba9193
+	        }
ba9193
+	        curr->nextDrawPriv = NULL;
ba9193
+	        __glXUnrefDrawable(glxc->drawPriv);
ba9193
+	        break;
ba9193
 	    }
ba9193
-	    curr->nextDrawPriv = NULL;
ba9193
-	    __glXUnrefDrawable(glxc->drawPriv);
ba9193
-	    break;
ba9193
-	}
ba9193
+        }
ba9193
     }
ba9193
 
ba9193
-
ba9193
     prev = NULL;
ba9193
-    for ( curr = glxc->readPriv->readGlxc
331a92
-	  ; curr != NULL
ba9193
-	  ; prev = curr, curr = curr->nextReadPriv ) {
ba9193
-	if (curr == glxc) {
ba9193
-	    /* found context.  Deassociate. */
ba9193
-	    if (prev == NULL) {
ba9193
-		glxc->readPriv->readGlxc = curr->nextReadPriv;
ba9193
-	    } else {
ba9193
-		prev->nextReadPriv = curr->nextReadPriv;
ba9193
-	    }
ba9193
-	    curr->nextReadPriv = NULL;
ba9193
-	    __glXUnrefDrawable(glxc->readPriv);
ba9193
-	    break;
ba9193
-	}
ba9193
+    if (glxc->readPriv) {
ba9193
+        for ( curr = glxc->readPriv->readGlxc
ba9193
+	      ; curr != NULL 
ba9193
+	      ; prev = curr, curr = curr->nextReadPriv ) {
ba9193
+	    if (curr == glxc) {
ba9193
+	        /* found context.  Deassociate. */
ba9193
+	        if (prev == NULL) {
ba9193
+		    glxc->readPriv->readGlxc = curr->nextReadPriv;
ba9193
+	        } else {
ba9193
+		    prev->nextReadPriv = curr->nextReadPriv;
ba9193
+	        }
ba9193
+	        curr->nextReadPriv = NULL;
ba9193
+	        __glXUnrefDrawable(glxc->readPriv);
ba9193
+	       break;
ba9193
+	   }
ba9193
+       }
ba9193
     }
ba9193
 }
ba9193
 
ba9193
-- 
ba9193
1.5.4.1
ba9193