Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c	(revision 50567)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c	(revision 50568)
@@ -1243,5 +1243,7 @@
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     VBOXPtr pVBox = VBOXGetRec(pScrn);
-
+#if defined(VBOX_DRI) && !defined(VBOX_DRI_OLD)  /* DRI2 */
+    BOOL fRestore = TRUE;
+#endif
     if (pScrn->vtSema)
     {
@@ -1255,12 +1257,16 @@
     }
 #ifdef VBOX_DRI
+# ifndef VBOX_DRI_OLD  /* DRI2 */
+    if (   pVBox->drmFD >= 0
+        /* Tell the kernel driver, if present, that we are going away. */
+        && drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_ENABLE_HGSMI, NULL) >= 0)
+        fRestore = false;
+# endif
     if (pVBox->useDRI)
         VBOXDRICloseScreen(pScreen, pVBox);
     pVBox->useDRI = false;
-# ifndef VBOX_DRI_OLD  /* DRI2 */
-    if (   pVBox->drmFD < 0
-        /* Tell the kernel driver, if present, that we are going away. */
-        || drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_ENABLE_HGSMI, NULL) < 0)
-# endif
+#endif
+#if defined(VBOX_DRI) && !defined(VBOX_DRI_OLD)  /* DRI2 */
+    if (fRestore)
 #endif
         if (pScrn->vtSema)
