diff --git a/src/i830_driver.c b/src/i830_driver.c
index 32ca6c9..ab73871 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3710,6 +3710,12 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
        pI830->uxa_driver = NULL;
    }
 #endif
+   if (pI830->front_buffer) {
+	i830_set_pixmap_bo(pScreen->GetScreenPixmap(pScreen), NULL);
+	i830_free_memory(pScrn, pI830->front_buffer);
+   	pI830->front_buffer = NULL;
+   }
+
    xf86_cursors_fini (pScreen);
 
    i830_allocator_fini(pScrn);
diff --git a/src/i830_exa.c b/src/i830_exa.c
index 39011bc..2b3b42b 100644
--- a/src/i830_exa.c
+++ b/src/i830_exa.c
@@ -812,7 +812,8 @@ i830_set_pixmap_bo(PixmapPtr pixmap, dri_bo *bo)
 	dri_bo_unreference (old_bo);
 #if I830_USE_UXA
     if (i830->accel == ACCEL_UXA) {
-	dri_bo_reference(bo);
+	if (bo != NULL)
+	    dri_bo_reference(bo);
 	dixSetPrivate(&pixmap->devPrivates, &uxa_pixmap_index, bo);
     }
 #endif
@@ -821,7 +822,8 @@ i830_set_pixmap_bo(PixmapPtr pixmap, dri_bo *bo)
 	struct i830_exa_pixmap_priv *driver_priv =
 	    exaGetPixmapDriverPrivate(pixmap);
 	if (driver_priv) {
-	    dri_bo_reference(bo);
+	    if (bo != NULL)
+	    	dri_bo_reference(bo);
 	    driver_priv->bo = bo;
 	}
     }
