check for null ptr in xm_buffer_unreference()
authorBrian <brian.paul@tungstengraphics.com>
Thu, 23 Aug 2007 20:39:51 +0000 (21:39 +0100)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 23 Aug 2007 20:39:51 +0000 (21:39 +0100)
src/mesa/drivers/x11/xm_softpipe.c

index 432f306e94ea5a283a9e51fb9c3acdecd9d59252..ff33ad785090d651e778ec08a9015c5cdfdc3981 100644 (file)
@@ -112,17 +112,19 @@ xm_buffer_reference(struct pipe_winsys *pws, struct pipe_buffer_handle *buf)
 static void
 xm_buffer_unreference(struct pipe_winsys *pws, struct pipe_buffer_handle **buf)
 {
-   struct xm_buffer *xm_buf = xm_bo(*buf);
-   xm_buf->refcount--;
-   assert(xm_buf->refcount >= 0);
-   if (xm_buf->refcount == 0) {
-      if (xm_buf->data) {
-         free(xm_buf->data);
-         xm_buf->data = NULL;
+   if (*buf) {
+      struct xm_buffer *xm_buf = xm_bo(*buf);
+      xm_buf->refcount--;
+      assert(xm_buf->refcount >= 0);
+      if (xm_buf->refcount == 0) {
+         if (xm_buf->data) {
+            free(xm_buf->data);
+            xm_buf->data = NULL;
+         }
+         free(xm_buf);
       }
-      free(xm_buf);
+      *buf = NULL;
    }
-   *buf = NULL;
 }
 
 static void