Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 52998)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 52999)
@@ -1027,5 +1027,8 @@
     /* Create action-pool: */
     m_pActionPool = UIActionPool::create(UIActionPoolType_Runtime);
-    m_pActionPool->toRuntime()->setSession(this);
+    AssertPtrReturnVoid(actionPool());
+    {
+        /* Configure action-pool: */
+        actionPool()->toRuntime()->setSession(this);
 
         /* Get host/machine: */
@@ -1109,4 +1112,5 @@
         }
 #endif /* Q_WS_MAC */
+    }
 }
 
@@ -1258,5 +1262,9 @@
 
         /* Remember if guest should autoresize: */
-        gEDataManager->setGuestScreenAutoResizeEnabled(actionPool()->action(UIActionIndexRT_M_View_T_GuestAutoresize)->isChecked(), vboxGlobal().managedVMUuid());
+        if (actionPool())
+        {
+            const QAction *pGuestAutoresizeSwitch = actionPool()->action(UIActionIndexRT_M_View_T_GuestAutoresize);
+            gEDataManager->setGuestScreenAutoResizeEnabled(pGuestAutoresizeSwitch->isChecked(), vboxGlobal().managedVMUuid());
+        }
 
 #ifndef Q_WS_MAC
@@ -1273,9 +1281,9 @@
     for (int i = m_frameBufferVector.size() - 1; i >= 0; --i)
     {
-        UIFrameBuffer *pFb = m_frameBufferVector[i];
-        if (pFb)
+        UIFrameBuffer *pFrameBuffer = m_frameBufferVector[i];
+        if (pFrameBuffer)
         {
             /* Mark framebuffer as unused: */
-            pFb->setMarkAsUnused(true);
+            pFrameBuffer->setMarkAsUnused(true);
             /* Detach framebuffer from Display: */
             CDisplay display = session().GetConsole().GetDisplay();
@@ -1291,5 +1299,6 @@
 void UISession::cleanupConsoleEventHandlers()
 {
-    /* Destroy console event-handler: */
+    /* Destroy console event-handler if necessary: */
+    if (gConsoleEvents)
         UIConsoleEventHandler::destroy();
 }
@@ -1306,10 +1315,12 @@
 {
 #ifdef Q_WS_MAC
+    /* Destroy Mac OS X menu-bar: */
     delete m_pMenuBar;
     m_pMenuBar = 0;
 #endif /* Q_WS_MAC */
 
-    /* Destroy action-pool: */
-    UIActionPool::destroy(m_pActionPool);
+    /* Destroy action-pool if necessary: */
+    if (actionPool())
+        UIActionPool::destroy(actionPool());
 }
 
