Index: /trunk/src/VBox/Main/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 22623)
+++ /trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 22624)
@@ -1823,6 +1823,6 @@
                     FALSE /* aCancelable */);
 
-    bool beganSavingState = false;
-    bool taskCreationFailed = false;
+    bool fBeganSavingState = false;
+    bool fTaskCreationFailed = false;
 
     do
@@ -1839,5 +1839,5 @@
         if (FAILED (rc))
         {
-            taskCreationFailed = true;
+            fTaskCreationFailed = true;
             break;
         }
@@ -1853,5 +1853,5 @@
         CheckComRCBreakRC (rc);
 
-        beganSavingState = true;
+        fBeganSavingState = true;
 
         /* sync the state with the server */
@@ -1896,10 +1896,10 @@
     while (0);
 
-    if (FAILED (rc) && !taskCreationFailed)
+    if (FAILED (rc) && !fTaskCreationFailed)
     {
         /* preserve existing error info */
         ErrorInfoKeeper eik;
 
-        if (beganSavingState)
+        if (fBeganSavingState)
         {
             /*
@@ -2363,6 +2363,7 @@
 }
 
-STDMETHODIMP Console::TakeSnapshot (IN_BSTR aName, IN_BSTR aDescription,
-                                    IProgress **aProgress)
+STDMETHODIMP Console::TakeSnapshot(IN_BSTR aName,
+                                   IN_BSTR aDescription,
+                                   IProgress **aProgress)
 {
     LogFlowThisFuncEnter();
@@ -2377,11 +2378,8 @@
     AutoWriteLock alock(this);
 
-    if (Global::IsTransient (mMachineState))
-    {
-        return setError (VBOX_E_INVALID_VM_STATE,
-            tr ("Cannot take a snapshot of the machine "
-                "while it is changing the state (machine state: %d)"),
-            mMachineState);
-    }
+    if (Global::IsTransient(mMachineState))
+        return setError(VBOX_E_INVALID_VM_STATE,
+                        tr("Cannot take a snapshot of the machine while it is changing the state (machine state: %d)"),
+                        mMachineState);
 
     /* memorize the current machine state */
@@ -2396,5 +2394,5 @@
     HRESULT rc = S_OK;
 
-    bool takingSnapshotOnline = mMachineState == MachineState_Paused;
+    bool fTakingSnapshotOnline = (mMachineState == MachineState_Paused);
 
     /*
@@ -2403,21 +2401,21 @@
      */
     ComObjPtr<Progress> saveProgress;
-    if (takingSnapshotOnline)
+    if (fTakingSnapshotOnline)
     {
         saveProgress.createObject();
-        rc = saveProgress->init (FALSE, 1, Bstr (tr ("Saving the execution state")));
+        rc = saveProgress->init(FALSE, 1, Bstr(tr("Saving the execution state")));
         AssertComRCReturn (rc, rc);
     }
 
-    bool beganTakingSnapshot = false;
-    bool taskCreationFailed = false;
+    bool fBeganTakingSnapshot = false;
+    bool fTaskCreationFailed = false;
 
     do
     {
         /* create a task object early to ensure mpVM protection is successful */
-        std::auto_ptr <VMSaveTask> task;
-        if (takingSnapshotOnline)
-        {
-            task.reset (new VMSaveTask (this, saveProgress));
+        std::auto_ptr<VMSaveTask> task;
+        if (fTakingSnapshotOnline)
+        {
+            task.reset(new VMSaveTask(this, saveProgress));
             rc = task->rc();
             /*
@@ -2429,5 +2427,5 @@
             if (FAILED (rc))
             {
-                taskCreationFailed = true;
+                fTaskCreationFailed = true;
                 break;
             }
@@ -2442,7 +2440,10 @@
          *  others from accessing this machine)
          */
-        rc = mControl->BeginTakingSnapshot (this, aName, aDescription,
-                                            saveProgress, stateFilePath.asOutParam(),
-                                            serverProgress.asOutParam());
+        rc = mControl->BeginTakingSnapshot(this,
+                                           aName,
+                                           aDescription,
+                                           saveProgress,
+                                           stateFilePath.asOutParam(),
+                                           serverProgress.asOutParam());
         if (FAILED (rc))
             break;
@@ -2452,13 +2453,12 @@
          *  (i.e. creating a snapshot online)
          */
-        ComAssertBreak (
-            (!stateFilePath.isNull() && takingSnapshotOnline) ||
-            (stateFilePath.isNull() && !takingSnapshotOnline),
-            rc = E_FAIL);
-
-        beganTakingSnapshot = true;
+        ComAssertBreak(    (!stateFilePath.isNull() && fTakingSnapshotOnline)
+                        || (stateFilePath.isNull() && !fTakingSnapshotOnline),
+                       rc = E_FAIL);
+
+        fBeganTakingSnapshot = true;
 
         /* sync the state with the server */
-        setMachineStateLocally (MachineState_Saving);
+        setMachineStateLocally(MachineState_Saving);
 
         /*
@@ -2467,10 +2467,11 @@
          */
         ComObjPtr<CombinedProgress> combinedProgress;
-        if (takingSnapshotOnline)
+        if (fTakingSnapshotOnline)
         {
             combinedProgress.createObject();
-            rc = combinedProgress->init (static_cast <IConsole *> (this),
-                                         Bstr (tr ("Taking snapshot of virtual machine")),
-                                         serverProgress, saveProgress);
+            rc = combinedProgress->init(static_cast<IConsole*>(this),
+                                        Bstr(tr("Taking snapshot of virtual machine")),
+                                        serverProgress,
+                                        saveProgress);
             AssertComRCBreakRC (rc);
 
@@ -2483,9 +2484,15 @@
 
             /* create a thread to wait until the VM state is saved */
-            int vrc = RTThreadCreate (NULL, Console::saveStateThread, (void *) task.get(),
-                                      0, RTTHREADTYPE_MAIN_WORKER, 0, "VMTakeSnap");
-
-            ComAssertMsgRCBreak (vrc, ("Could not create VMTakeSnap thread (%Rrc)", vrc),
-                                 rc = E_FAIL);
+            int vrc = RTThreadCreate(NULL,
+                                     Console::saveStateThread,
+                                     (void*)task.get(),
+                                     0,
+                                     RTTHREADTYPE_MAIN_WORKER,
+                                     0,
+                                     "VMTakeSnap");
+
+            ComAssertMsgRCBreak(vrc,
+                                ("Could not create VMTakeSnap thread (%Rrc)", vrc),
+                                rc = E_FAIL);
 
             /* task is now owned by saveStateThread(), so release it */
@@ -2501,13 +2508,12 @@
                 serverProgress.queryInterfaceTo(aProgress);
         }
-    }
-    while (0);
-
-    if (FAILED (rc) && !taskCreationFailed)
+    } while (0);
+
+    if (FAILED(rc) && !fTaskCreationFailed)
     {
         /* preserve existing error info */
         ErrorInfoKeeper eik;
 
-        if (beganTakingSnapshot && takingSnapshotOnline)
+        if (fBeganTakingSnapshot && fTakingSnapshotOnline)
         {
             /*
@@ -2517,5 +2523,5 @@
              *  before calling mControl->BeginTakingSnapshot().
              */
-            mControl->EndTakingSnapshot (FALSE);
+            mControl->EndTakingSnapshot(FALSE);
         }
 
@@ -2523,10 +2529,10 @@
         {
             /* restore the paused state if appropriate */
-            setMachineStateLocally (MachineState_Paused);
+            setMachineStateLocally(MachineState_Paused);
             /* restore the running state if appropriate */
             Resume();
         }
         else
-            setMachineStateLocally (lastMachineState);
+            setMachineStateLocally(lastMachineState);
     }
 
@@ -2536,5 +2542,5 @@
 }
 
-STDMETHODIMP Console::DiscardSnapshot (IN_BSTR aId, IProgress **aProgress)
+STDMETHODIMP Console::DiscardSnapshot(IN_BSTR aId, IProgress **aProgress)
 {
     CheckComArgExpr(aId, Guid (aId).isEmpty() == false);
Index: /trunk/src/VBox/Main/HardDiskImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/HardDiskImpl.cpp	(revision 22623)
+++ /trunk/src/VBox/Main/HardDiskImpl.cpp	(revision 22624)
@@ -2544,4 +2544,6 @@
     AssertReturn(mm.type != HardDiskType_Writethrough, E_FAIL);
 
+    LogFlowThisFunc(("Hard disk '%s' has media status %d\n", name().raw(), m.state));
+
     /* Note: MediaState_LockedWrite is ok when taking an online snapshot */
     AssertReturn(m.state == MediaState_LockedRead ||
@@ -2555,5 +2557,6 @@
     /* check that the hard disk is not attached to any VM in the current state*/
     for (BackRefList::const_iterator it = m.backRefs.begin();
-         it != m.backRefs.end(); ++ it)
+         it != m.backRefs.end();
+         ++it)
     {
         if (it->inCurState)
@@ -2590,8 +2593,9 @@
         {
             progress.createObject();
-            rc = progress->init (mVirtualBox, static_cast<IHardDisk*> (this),
-                BstrFmt (tr ("Creating differencing hard disk storage unit '%ls'"),
-                         aTarget->m.locationFull.raw()),
-                TRUE /* aCancelable */);
+            rc = progress->init(mVirtualBox,
+                                static_cast<IHardDisk*>(this),
+                                BstrFmt(tr("Creating differencing hard disk storage unit '%ls'"),
+                                           aTarget->m.locationFull.raw()),
+                                TRUE /* aCancelable */);
             CheckComRCReturnRC(rc);
         }
@@ -2601,5 +2605,5 @@
      * asynchronously */
 
-    std::auto_ptr <Task> task (new Task (this, progress, Task::CreateDiff));
+    std::auto_ptr<Task> task(new Task(this, progress, Task::CreateDiff));
     AssertComRCReturnRC(task->autoCaller.rc());
 
@@ -2608,5 +2612,5 @@
 
     /* register a task (it will deregister itself when done) */
-    ++ mm.numCreateDiffTasks;
+    ++mm.numCreateDiffTasks;
     Assert (mm.numCreateDiffTasks != 0); /* overflow? */
 
@@ -3972,5 +3976,5 @@
             /* deregister the task registered in createDiffStorage() */
             Assert (that->mm.numCreateDiffTasks != 0);
-            -- that->mm.numCreateDiffTasks;
+            --that->mm.numCreateDiffTasks;
 
             /* Note that in sync mode, it's the caller's responsibility to
Index: /trunk/src/VBox/Main/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MachineImpl.cpp	(revision 22623)
+++ /trunk/src/VBox/Main/MachineImpl.cpp	(revision 22624)
@@ -5894,4 +5894,5 @@
 
         data.strNotificationPatterns = mHWData->mGuestPropertyNotificationPatterns;
+#endif /* VBOX_WITH_GUEST_PROPS defined */
     }
     catch(std::bad_alloc &)
@@ -5899,5 +5900,4 @@
         return E_OUTOFMEMORY;
     }
-#endif /* VBOX_WITH_GUEST_PROPS defined */
 
     AssertComRC(rc);
@@ -6114,8 +6114,8 @@
                 ComObjPtr<HardDisk> hd = hda->hardDisk();
 
-                rc = hd->LockRead (NULL);
+                rc = hd->LockRead(NULL);
                 CheckComRCThrowRC(rc);
 
-                lockedMedia.push_back (hd);
+                lockedMedia.push_back(hd);
             }
         }
@@ -6131,6 +6131,7 @@
          * disks and attach them */
 
-        for (HDData::AttachmentList::const_iterator
-             it = atts.begin(); it != atts.end(); ++ it)
+        for (HDData::AttachmentList::const_iterator it = atts.begin();
+             it != atts.end();
+             ++it)
         {
             ComObjPtr<HardDiskAttachment> hda = *it;
@@ -6141,6 +6142,5 @@
             {
                 /* copy the attachment as is */
-
-                Assert (hd->type() == HardDiskType_Writethrough);
+                Assert(hd->type() == HardDiskType_Writethrough);
 
                 rc = aProgress->setNextOperation(BstrFmt(tr("Skipping writethrough hard disk '%s'"),
@@ -6149,10 +6149,9 @@
                 CheckComRCThrowRC(rc);
 
-                mHDData->mAttachments.push_back (hda);
+                mHDData->mAttachments.push_back(hda);
                 continue;
             }
 
             /* need a diff */
-
             rc = aProgress->setNextOperation(BstrFmt(tr("Creating differencing hard disk for '%s'"),
                                                      hd->root()->name().raw()),
@@ -6171,6 +6170,9 @@
             alock.leave();
 
-            rc = hd->createDiffStorageAndWait (diff, HardDiskVariant_Standard,
-                                               &aProgress);
+            LogFlowThisFunc(("Calling createDiffStorageAndWait() on hard disk '%s'\n", hd->root()->name().raw()));
+
+            rc = hd->createDiffStorageAndWait(diff,
+                                              HardDiskVariant_Standard,
+                                              &aProgress);
 
             alock.enter();
@@ -6178,15 +6180,18 @@
             CheckComRCThrowRC(rc);
 
-            rc = diff->attachTo (mData->mUuid);
-            AssertComRCThrowRC (rc);
+            rc = diff->attachTo(mData->mUuid);
+            AssertComRCThrowRC(rc);
 
             /* add a new attachment */
             ComObjPtr<HardDiskAttachment> attachment;
             attachment.createObject();
-            rc = attachment->init (diff, hda->controller(), hda->port(),
-                                   hda->device(), true /* aImplicit */);
+            rc = attachment->init(diff,
+                                  hda->controller(),
+                                  hda->port(),
+                                  hda->device(),
+                                  true /* aImplicit */);
             CheckComRCThrowRC(rc);
 
-            mHDData->mAttachments.push_back (attachment);
+            mHDData->mAttachments.push_back(attachment);
         }
     }
@@ -6199,7 +6204,8 @@
 
         for (LockedMedia::const_iterator it = lockedMedia.begin();
-             it != lockedMedia.end(); ++ it)
-        {
-            HRESULT rc2 = (*it)->UnlockRead (NULL);
+             it != lockedMedia.end();
+             ++it)
+        {
+            HRESULT rc2 = (*it)->UnlockRead(NULL);
             AssertComRC(rc2);
         }
@@ -7013,24 +7019,35 @@
 
 /** Take snapshot task */
-struct SessionMachine::TakeSnapshotTask : public SessionMachine::Task
-{
-    TakeSnapshotTask (SessionMachine *m)
-        : Task (m, NULL) {}
-
-    void handler() { machine->takeSnapshotHandler (*this); }
+struct SessionMachine::TakeSnapshotTask
+    : public SessionMachine::Task
+{
+    TakeSnapshotTask(SessionMachine *m)
+        : Task(m, NULL)
+    {}
+
+    void handler()
+    {
+        machine->takeSnapshotHandler(*this);
+    }
 };
 
 /** Discard snapshot task */
-struct SessionMachine::DiscardSnapshotTask : public SessionMachine::Task
-{
-    DiscardSnapshotTask (SessionMachine *m, Progress *p, Snapshot *s)
-        : Task (m, p)
-        , snapshot (s) {}
+struct SessionMachine::DiscardSnapshotTask
+    : public SessionMachine::Task
+{
+    DiscardSnapshotTask(SessionMachine *m, Progress *p, Snapshot *s)
+        : Task (m, p),
+          snapshot (s)
+    {}
 
     DiscardSnapshotTask (const Task &task, Snapshot *s)
         : Task (task)
-        , snapshot (s) {}
-
-    void handler() { machine->discardSnapshotHandler (*this); }
+        , snapshot (s)
+    {}
+
+    void handler()
+    {
+        machine->discardSnapshotHandler(*this);
+    }
 
     ComObjPtr<Snapshot> snapshot;
@@ -7038,11 +7055,16 @@
 
 /** Discard current state task */
-struct SessionMachine::DiscardCurrentStateTask : public SessionMachine::Task
-{
-    DiscardCurrentStateTask (SessionMachine *m, Progress *p,
-                             bool discardCurSnapshot)
-        : Task (m, p), discardCurrentSnapshot (discardCurSnapshot) {}
-
-    void handler() { machine->discardCurrentStateHandler (*this); }
+struct SessionMachine::DiscardCurrentStateTask
+    : public SessionMachine::Task
+{
+    DiscardCurrentStateTask(SessionMachine *m, Progress *p, bool discardCurSnapshot)
+        : Task(m, p),
+          discardCurrentSnapshot(discardCurSnapshot)
+    {}
+
+    void handler()
+    {
+        machine->discardCurrentStateHandler(*this);
+    }
 
     const bool discardCurrentSnapshot;
@@ -7051,5 +7073,5 @@
 ////////////////////////////////////////////////////////////////////////////////
 
-DEFINE_EMPTY_CTOR_DTOR (SessionMachine)
+DEFINE_EMPTY_CTOR_DTOR(SessionMachine)
 
 HRESULT SessionMachine::FinalConstruct()
@@ -7874,8 +7896,10 @@
  *  @note Locks mParent + this object for writing.
  */
-STDMETHODIMP SessionMachine::BeginTakingSnapshot (
-    IConsole *aInitiator, IN_BSTR aName, IN_BSTR aDescription,
-    IProgress *aProgress, BSTR *aStateFilePath,
-    IProgress **aServerProgress)
+STDMETHODIMP SessionMachine::BeginTakingSnapshot(IConsole *aInitiator,
+                                                 IN_BSTR aName,
+                                                 IN_BSTR aDescription,
+                                                 IProgress *aProgress,
+                                                 BSTR *aStateFilePath,
+                                                 IProgress **aServerProgress)
 {
     LogFlowThisFuncEnter();
@@ -7892,15 +7916,16 @@
     AutoMultiWriteLock2 alock (mParent, this);
 
-    AssertReturn((!Global::IsOnlineOrTransient (mData->mMachineState) ||
-                   mData->mMachineState == MachineState_Paused) &&
-                  mSnapshotData.mLastState == MachineState_Null &&
-                  mSnapshotData.mSnapshot.isNull() &&
-                  mSnapshotData.mServerProgress.isNull() &&
-                  mSnapshotData.mCombinedProgress.isNull(),
-                  E_FAIL);
-
-    bool takingSnapshotOnline = mData->mMachineState == MachineState_Paused;
-
-    if (!takingSnapshotOnline && mData->mMachineState != MachineState_Saved)
+    AssertReturn(    (    !Global::IsOnlineOrTransient (mData->mMachineState)
+                       || mData->mMachineState == MachineState_Paused
+                     )
+                  && mSnapshotData.mLastState == MachineState_Null
+                  && mSnapshotData.mSnapshot.isNull()
+                  && mSnapshotData.mServerProgress.isNull()
+                  && mSnapshotData.mCombinedProgress.isNull(), E_FAIL);
+
+    bool fTakingSnapshotOnline = (mData->mMachineState == MachineState_Paused);
+
+    if (    !fTakingSnapshotOnline
+         && mData->mMachineState != MachineState_Saved)
     {
         /* save all current settings to ensure current changes are committed and
@@ -7929,5 +7954,5 @@
 #endif
 
-    AssertReturn(aProgress || !takingSnapshotOnline, E_FAIL);
+    AssertReturn(aProgress || !fTakingSnapshotOnline, E_FAIL);
 
     /* create an ID for the snapshot */
@@ -7937,9 +7962,10 @@
     Bstr stateFilePath;
     /* stateFilePath is null when the machine is not online nor saved */
-    if (takingSnapshotOnline || mData->mMachineState == MachineState_Saved)
-        stateFilePath = Utf8StrFmt ("%ls%c{%RTuuid}.sav",
-                                    mUserData->mSnapshotFolderFull.raw(),
-                                    RTPATH_DELIMITER,
-                                    snapshotId.ptr());
+    if (    fTakingSnapshotOnline
+         || mData->mMachineState == MachineState_Saved)
+        stateFilePath = BstrFmt("%ls%c{%RTuuid}.sav",
+                                mUserData->mSnapshotFolderFull.raw(),
+                                RTPATH_DELIMITER,
+                                snapshotId.ptr());
 
     /* ensure the directory for the saved state file exists */
@@ -7953,10 +7979,10 @@
     ComObjPtr<SnapshotMachine> snapshotMachine;
     snapshotMachine.createObject();
-    HRESULT rc = snapshotMachine->init (this, snapshotId, stateFilePath);
+    HRESULT rc = snapshotMachine->init(this, snapshotId, stateFilePath);
     AssertComRCReturn (rc, rc);
 
-    Bstr progressDesc = BstrFmt (tr ("Taking snapshot of virtual machine '%ls'"),
-                                 mUserData->mName.raw());
-    Bstr firstOpDesc = Bstr (tr ("Preparing to take snapshot"));
+    Bstr progressDesc = BstrFmt(tr("Taking snapshot of virtual machine '%ls'"),
+                                mUserData->mName.raw());
+    Bstr firstOpDesc = Bstr(tr("Preparing to take snapshot"));
 
     /* create a server-side progress object (it will be descriptionless when we
@@ -7971,9 +7997,9 @@
         if (mData->mMachineState == MachineState_Saved)
             opCount ++;
-        if (takingSnapshotOnline)
-            rc = serverProgress->init (FALSE, opCount, firstOpDesc);
+        if (fTakingSnapshotOnline)
+            rc = serverProgress->init(FALSE, opCount, firstOpDesc);
         else
-            rc = serverProgress->init (mParent, aInitiator, progressDesc, FALSE,
-                                       opCount, firstOpDesc);
+            rc = serverProgress->init(mParent, aInitiator, progressDesc, FALSE,
+                                      opCount, firstOpDesc);
         AssertComRCReturn (rc, rc);
     }
@@ -7981,5 +8007,5 @@
     /* create a combined server-side progress object when necessary */
     ComObjPtr<CombinedProgress> combinedProgress;
-    if (takingSnapshotOnline)
+    if (fTakingSnapshotOnline)
     {
         combinedProgress.createObject();
@@ -8004,8 +8030,12 @@
     /* create and start the task on a separate thread (note that it will not
      * start working until we release alock) */
-    TakeSnapshotTask *task = new TakeSnapshotTask (this);
-    int vrc = RTThreadCreate (NULL, taskHandler,
-                              (void *) task,
-                              0, RTTHREADTYPE_MAIN_WORKER, 0, "TakeSnapshot");
+    TakeSnapshotTask *task = new TakeSnapshotTask(this);
+    int vrc = RTThreadCreate(NULL,
+                             taskHandler,
+                             (void*)task,
+                             0,
+                             RTTHREADTYPE_MAIN_WORKER,
+                             0,
+                             "TakeSnapshot");
     if (RT_FAILURE(vrc))
     {
@@ -8022,7 +8052,7 @@
 
     /* set the state to Saving (this is expected by Console::TakeSnapshot()) */
-    setMachineState (MachineState_Saving);
-
-    if (takingSnapshotOnline)
+    setMachineState(MachineState_Saving);
+
+    if (fTakingSnapshotOnline)
         stateFilePath.cloneTo(aStateFilePath);
     else
@@ -8038,5 +8068,5 @@
  * @note Locks this object for writing.
  */
-STDMETHODIMP SessionMachine::EndTakingSnapshot (BOOL aSuccess)
+STDMETHODIMP SessionMachine::EndTakingSnapshot(BOOL aSuccess)
 {
     LogFlowThisFunc(("\n"));
@@ -8058,7 +8088,7 @@
      * (this is expected by Console::TakeSnapshot() and
      * Console::saveStateThread()) */
-    setMachineState (mSnapshotData.mLastState);
-
-    return endTakingSnapshot (aSuccess);
+    setMachineState(mSnapshotData.mLastState);
+
+    return endTakingSnapshot(aSuccess);
 }
 
@@ -8930,5 +8960,7 @@
 /**
  * Helper method to finalize taking a snapshot. Gets called to finalize the
- * "take snapshot" procedure.
+ * "take snapshot" procedure, either from the public SessionMachine::EndTakingSnapshot()
+ * if taking the snapshot failed/was aborted or from the takeSnapshotHandler thread
+ * when taking the snapshot succeeded.
  *
  * Expected to be called after completing *all* the tasks related to taking the
@@ -8939,5 +8971,5 @@
  * @note Locks this objects for writing.
  */
-HRESULT SessionMachine::endTakingSnapshot (BOOL aSuccess)
+HRESULT SessionMachine::endTakingSnapshot(BOOL aSuccess)
 {
     LogFlowThisFuncEnter();
@@ -8956,5 +8988,5 @@
     {
         /* the server progress must be completed on success */
-        Assert (mSnapshotData.mServerProgress->completed());
+        Assert(mSnapshotData.mServerProgress->completed());
 
         mData->mCurrentSnapshot = mSnapshotData.mSnapshot;
@@ -8964,5 +8996,5 @@
             mData->mFirstSnapshot = mData->mCurrentSnapshot;
 
-        if (!Global::IsOnline (mSnapshotData.mLastState))
+        if (!Global::IsOnline(mSnapshotData.mLastState))
             /* the machine was powered off or saved when taking a snapshot, so
              * reset the mCurrentStateModified flag */
@@ -9018,6 +9050,7 @@
 
 /**
- * Take snapshot task handler. Must be called only by
- * TakeSnapshotTask::handler()!
+ * Take snapshot task handler.
+ * This gets called from TakeSnapshotTask::handler(), which got created by
+ * SnapshotMachine::BeginTakingSnapshot().
  *
  * The sole purpose of this task is to asynchronously create differencing VDIs
@@ -9027,5 +9060,5 @@
  * @note Locks this object for writing.
  */
-void SessionMachine::takeSnapshotHandler (TakeSnapshotTask & /* aTask */)
+void SessionMachine::takeSnapshotHandler(TakeSnapshotTask & /* aTask */)
 {
     LogFlowThisFuncEnter();
@@ -9046,17 +9079,18 @@
     HRESULT rc = S_OK;
 
-    bool online = Global::IsOnline (mSnapshotData.mLastState);
+    bool online = Global::IsOnline(mSnapshotData.mLastState);
 
     LogFlowThisFunc(("Creating differencing hard disks (online=%d)...\n",
-                      online));
+                     online));
 
     mHDData.backup();
 
     /* create new differencing hard disks and attach them to this machine */
-    rc = createImplicitDiffs (mUserData->mSnapshotFolderFull,
-                              mSnapshotData.mServerProgress,
-                              online);
-
-    if (SUCCEEDED(rc) && mSnapshotData.mLastState == MachineState_Saved)
+    rc = createImplicitDiffs(mUserData->mSnapshotFolderFull,
+                             mSnapshotData.mServerProgress,
+                             online);
+
+    if (    SUCCEEDED(rc)
+         && mSnapshotData.mLastState == MachineState_Saved)
     {
         Utf8Str stateFrom = mSSData->mStateFilePath;
@@ -9071,5 +9105,4 @@
         /* Leave the lock before a lengthy operation (mMachineState is
          * MachineState_Saving here) */
-
         alock.leave();
 
@@ -9101,12 +9134,12 @@
             ErrorInfoKeeper eik;
 
-            setMachineState (mSnapshotData.mLastState);
+            setMachineState(mSnapshotData.mLastState);
             updateMachineStateOnClient();
         }
 
         /* finalize the progress after setting the state, for consistency */
-        mSnapshotData.mServerProgress->notifyComplete (rc);
-
-        endTakingSnapshot (SUCCEEDED(rc));
+        mSnapshotData.mServerProgress->notifyComplete(rc);
+
+        endTakingSnapshot(SUCCEEDED(rc));
     }
     else
@@ -9373,5 +9406,5 @@
     catch (HRESULT aRC) { rc = aRC; }
 
-    if FAILED(rc)
+    if (FAILED(rc))
     {
         HRESULT rc2 = S_OK;
Index: /trunk/src/VBox/Main/MediumImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MediumImpl.cpp	(revision 22623)
+++ /trunk/src/VBox/Main/MediumImpl.cpp	(revision 22624)
@@ -396,5 +396,5 @@
  *       in-process calls).
  */
-STDMETHODIMP MediumBase::LockWrite (MediaState_T *aState)
+STDMETHODIMP MediumBase::LockWrite(MediaState_T *aState)
 {
     AutoCaller autoCaller(this);
Index: /trunk/src/VBox/Main/SnapshotImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/SnapshotImpl.cpp	(revision 22623)
+++ /trunk/src/VBox/Main/SnapshotImpl.cpp	(revision 22624)
@@ -346,5 +346,5 @@
 }
 
-STDMETHODIMP Snapshot::COMGETTER(Online) (BOOL *aOnline)
+STDMETHODIMP Snapshot::COMGETTER(Online)(BOOL *aOnline)
 {
     CheckComArgOutPointerValid(aOnline);
Index: /trunk/src/VBox/Main/VirtualBoxImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 22623)
+++ /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 22624)
@@ -4280,5 +4280,5 @@
  */
 HRESULT VirtualBox::unregisterDHCPServer(DHCPServer *aDHCPServer,
-                                       bool aSaveRegistry /*= true*/)
+                                         bool aSaveRegistry /*= true*/)
 {
     AssertReturn(aDHCPServer != NULL, E_INVALIDARG);
Index: /trunk/src/VBox/Main/include/MachineImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MachineImpl.h	(revision 22623)
+++ /trunk/src/VBox/Main/include/MachineImpl.h	(revision 22624)
@@ -917,5 +917,5 @@
     NS_DECL_ISUPPORTS
 
-    DECLARE_EMPTY_CTOR_DTOR (SessionMachine)
+    DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
 
     HRESULT FinalConstruct();
Index: /trunk/src/VBox/Main/include/SnapshotImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/SnapshotImpl.h	(revision 22623)
+++ /trunk/src/VBox/Main/include/SnapshotImpl.h	(revision 22624)
@@ -91,5 +91,5 @@
     // public methods only for internal purposes
 
-    const Bstr &stateFilePath() const;
+    const Bstr& stateFilePath() const;
 
     ComObjPtr<Snapshot> parent() const
Index: /trunk/src/VBox/Main/include/VirtualBoxImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/VirtualBoxImpl.h	(revision 22623)
+++ /trunk/src/VBox/Main/include/VirtualBoxImpl.h	(revision 22624)
@@ -79,11 +79,11 @@
 public:
 
-    typedef std::list <ComPtr<IVirtualBoxCallback> > CallbackList;
-    typedef std::vector <ComPtr<IVirtualBoxCallback> > CallbackVector;
-
-    typedef std::vector <ComObjPtr<SessionMachine> > SessionMachineVector;
-    typedef std::vector <ComObjPtr<Machine> > MachineVector;
-
-    typedef std::vector <ComPtr<IInternalSessionControl> > InternalControlVector;
+    typedef std::list< ComPtr<IVirtualBoxCallback> > CallbackList;
+    typedef std::vector< ComPtr<IVirtualBoxCallback> > CallbackVector;
+
+    typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector;
+    typedef std::vector< ComObjPtr<Machine> > MachineVector;
+
+    typedef std::vector< ComPtr<IInternalSessionControl> > InternalControlVector;
 
     class CallbackEvent;
@@ -107,5 +107,5 @@
     NS_DECL_ISUPPORTS
 
-    /* to postpone generation of the default ctor/dtor */
+    // to postpone generation of the default ctor/dtor
     VirtualBox();
     ~VirtualBox();
@@ -389,29 +389,27 @@
     Data mData;
 
+#if defined(RT_OS_WINDOWS)
+    #define UPDATEREQARG NULL
+    #define UPDATEREQTYPE HANDLE
+#elif defined(RT_OS_OS2)
+    #define UPDATEREQARG NIL_RTSEMEVENT
+    #define UPDATEREQTYPE RTSEMEVENT
+#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
+    #define UPDATEREQARG
+    #define UPDATEREQTYPE RTSEMEVENT
+#else
+# error "Port me!"
+#endif
+
     /** Client watcher thread data structure */
     struct ClientWatcherData
     {
         ClientWatcherData()
-#if defined(RT_OS_WINDOWS)
-            : mUpdateReq (NULL)
-#elif defined(RT_OS_OS2)
-            : mUpdateReq (NIL_RTSEMEVENT)
-#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
-            : mUpdateReq (NIL_RTSEMEVENT)
-#else
-# error "Port me!"
-#endif
-            , mThread (NIL_RTTHREAD) {}
+            : mUpdateReq(UPDATEREQARG),
+              mThread(NIL_RTTHREAD)
+        {}
 
         // const objects not requiring locking
-#if defined(RT_OS_WINDOWS)
-        const HANDLE mUpdateReq;
-#elif defined(RT_OS_OS2)
-        const RTSEMEVENT mUpdateReq;
-#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
-        const RTSEMEVENT mUpdateReq;
-#else
-# error "Port me!"
-#endif
+        const UPDATEREQTYPE mUpdateReq;
         const RTTHREAD mThread;
 
