Index: /trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp	(revision 54995)
+++ /trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp	(revision 54996)
@@ -15,4 +15,9 @@
  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
 #include "DrvAudioVRDE.h"
 #include "ConsoleImpl.h"
@@ -34,10 +39,12 @@
 #include <VBox/err.h>
 
-#ifdef LOG_GROUP
- #undef LOG_GROUP
-#endif
+#undef LOG_GROUP
 #define LOG_GROUP LOG_GROUP_DEV_AUDIO
 #include <VBox/log.h>
 
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
 /**
  * Audio VRDE driver instance data.
@@ -77,4 +84,6 @@
 } VRDESTREAMOUT, *PVRDESTREAMOUT;
 
+
+
 static DECLCALLBACK(int) drvAudioVRDEInit(PPDMIHOSTAUDIO pInterface)
 {
@@ -133,4 +142,6 @@
 
 /**
+ * <Missing brief description>
+ *
  * Transfers audio input formerly sent by a connected RDP client / VRDE backend
  * (using the onVRDEInputXXX methods) over to the VRDE host (VM). The audio device
@@ -182,4 +193,6 @@
 
 /**
+ * Transfers VM audio output to remote client.
+ *
  * Transfers VM audio output over to the VRDE instance for playing remotely
  * on the client.
@@ -474,8 +487,8 @@
 DECLCALLBACK(int) AudioVRDE::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
 {
+    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
+    PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
     AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
     AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
-
-    PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
 
     LogRel(("Audio: Initializing VRDE driver\n"));
@@ -503,9 +516,5 @@
     void *pvUser;
     int rc = CFGMR3QueryPtr(pCfg, "ObjectVRDPServer", &pvUser);
-    if (RT_FAILURE(rc))
-    {
-        AssertMsgFailed(("Confguration error: No/bad \"ObjectVRDPServer\" value, rc=%Rrc\n", rc));
-        return rc;
-    }
+    AssertMsgRCReturn(rc, ("Confguration error: No/bad \"ObjectVRDPServer\" value, rc=%Rrc\n", rc), rc);
 
     /* CFGM tree saves the pointer to ConsoleVRDPServer in the Object node of AudioVRDE. */
@@ -517,9 +526,5 @@
     pvUser = NULL;
     rc = CFGMR3QueryPtr(pCfg, "Object", &pvUser);
-    if (RT_FAILURE(rc))
-    {
-        AssertMsgFailed(("Confguration error: No/bad \"Object\" value, rc=%Rrc\n", rc));
-        return rc;
-    }
+    AssertMsgRCReturn(rc, ("Confguration error: No/bad \"Object\" value, rc=%Rrc\n", rc), rc);
 
     pThis->pAudioVRDE = (AudioVRDE *)pvUser;
@@ -531,18 +536,31 @@
      */
     pThis->pDrvAudio = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR);
-    if (!pThis->pDrvAudio)
-    {
-        AssertMsgFailed(("Configuration error: No upper interface specified!\n"));
-        return VERR_PDM_MISSING_INTERFACE_ABOVE;
-    }
-
-    return VINF_SUCCESS;
-}
-
+    AssertMsgReturn(pThis->pDrvAudio, ("Configuration error: No upper interface specified!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
+
+    return VINF_SUCCESS;
+}
+
+
+/**
+ * @interface_method_impl{PDMDRVREG,pfnDestruct}
+ */
 /* static */
 DECLCALLBACK(void) AudioVRDE::drvDestruct(PPDMDRVINS pDrvIns)
 {
+    PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
+    PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
     LogFlowFuncEnter();
-}
+
+    /*
+     * If the AudioVRDE object is still alive, we must clear it's reference to
+     * us since we'll be invalid when we return from this method.
+     */
+    if (pThis->pAudioVRDE)
+    {
+        pThis->pAudioVRDE->mpDrv = NULL;
+        pThis->pAudioVRDE = NULL;
+    }
+}
+
 
 /**
