Index: /trunk/src/VBox/Main/MediumImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MediumImpl.cpp	(revision 27830)
+++ /trunk/src/VBox/Main/MediumImpl.cpp	(revision 27831)
@@ -407,5 +407,5 @@
  * Thread function for time-consuming medium tasks.
  *
- * @param pvUser    Pointer to the std::auto_ptr<Medium::Task> instance.
+ * @param pvUser    Pointer to the Medium::Task instance.
  */
 /* static */
@@ -413,23 +413,20 @@
 {
     LogFlowFuncEnter();
-    /* pvUser is a pointer to a std::auto_ptr<Medium::Task>, which is so
-     * hard to understand that we just clear this situation now by copying
-     * it. This means the old object loses ownership, and task owns it. */
     AssertReturn(pvUser, (int)E_INVALIDARG);
-    std::auto_ptr<Medium::Task> *pTask =
-        static_cast<std::auto_ptr<Medium::Task> *>(pvUser);
-    std::auto_ptr<Medium::Task> task(pTask->release());
-    AssertReturn(task.get(), (int)E_INVALIDARG);
-
-    task->mThread = aThread;
-
-    HRESULT rc = task->handler();
+    Medium::Task *pTask = static_cast<Medium::Task *>(pvUser);
+
+    pTask->mThread = aThread;
+
+    HRESULT rc = pTask->handler();
 
     /* complete the progress if run asynchronously */
-    if (task->isAsync())
-    {
-        if (!task->mProgress.isNull())
-            task->mProgress->notifyComplete(rc);
-    }
+    if (pTask->isAsync())
+    {
+        if (!pTask->mProgress.isNull())
+            pTask->mProgress->notifyComplete(rc);
+    }
+
+    /* pTask is no longer needed, delete it. */
+    delete pTask;
 
     LogFlowFunc(("rc=%Rhrc\n", rc));
@@ -2469,10 +2466,15 @@
 
     /* setup task object to carry out the operation asynchronously */
-    std::auto_ptr<Medium::Task> task(new CreateBaseTask(this, progress,
-                                                        aLogicalSize,
-                                                        aVariant));
-    AssertComRCReturnRC(task->rc());
-
-    rc = startThread(task);
+    Medium::Task *pTask(new Medium::CreateBaseTask(this, progress,
+                                                   aLogicalSize, aVariant));
+    rc = pTask->rc();
+    if (FAILED(rc))
+    {
+        AssertComRC(rc);
+        delete pTask;
+        return rc;
+    }
+
+    rc = startThread(pTask);
     if (FAILED(rc)) return rc;
 
@@ -2480,4 +2482,6 @@
     m->state = MediumState_Creating;
 
+    progress.queryInterfaceTo(aProgress);
+
     return S_OK;
 }
@@ -2494,8 +2498,5 @@
     HRESULT rc = deleteStorageNoWait(progress);
     if (SUCCEEDED(rc))
-    {
-        /* return progress to the caller */
         progress.queryInterfaceTo(aProgress);
-    }
 
     return rc;
@@ -2536,8 +2537,5 @@
     }
     else
-    {
-        /* return progress to the caller */
         progress.queryInterfaceTo(aProgress);
-    }
 
     return rc;
@@ -2632,12 +2630,18 @@
 
         /* setup task object to carry out the operation asynchronously */
-        std::auto_ptr<Medium::Task> task(new CloneTask(this, progress,
-                                                       target, parent,
-                                                       sourceChain.release(),
-                                                       parentChain.release(),
-                                                       aVariant));
-        AssertComRCReturnRC(task->rc());
-
-        rc = startThread(task);
+        Medium::Task *pTask(new Medium::CloneTask(this, progress, target,
+                                                  parent,
+                                                  sourceChain.release(),
+                                                  parentChain.release(),
+                                                  aVariant));
+        rc = pTask->rc();
+        if (FAILED(rc))
+        {
+            AssertComRC(rc);
+            delete pTask;
+            throw rc;
+        }
+
+        rc = startThread(pTask);
         if (FAILED(rc)) throw rc;
 
@@ -2654,5 +2658,4 @@
 
     if (SUCCEEDED(rc))
-        /* return progress to the caller */
         progress.queryInterfaceTo(aProgress);
 
@@ -2702,9 +2705,15 @@
 
         /* setup task object to carry out the operation asynchronously */
-        std::auto_ptr<Medium::Task> task(new CompactTask(this, progress,
-                                                         imgChain.release()));
-        AssertComRCReturnRC(task->rc());
-
-        rc = startThread(task);
+        Medium::Task *pTask(new Medium::CompactTask(this, progress,
+                                                    imgChain.release()));
+        rc = pTask->rc();
+        if (FAILED(rc))
+        {
+            AssertComRC(rc);
+            delete pTask;
+            throw rc;
+        }
+
+        rc = startThread(pTask);
         if (FAILED(rc)) throw rc;
     }
@@ -2715,8 +2724,5 @@
 
     if (SUCCEEDED(rc))
-    {
-        /* return progress to the caller */
         progress.queryInterfaceTo(aProgress);
-    }
 
     return rc;
@@ -2772,8 +2778,14 @@
 
         /* setup task object to carry out the operation asynchronously */
-        std::auto_ptr<Medium::Task> task(new ResetTask(this, progress));
-        AssertComRCReturnRC(task->rc());
-
-        rc = startThread(task);
+        Medium::Task *pTask(new Medium::ResetTask(this, progress));
+        rc = pTask->rc();
+        if (FAILED(rc))
+        {
+            AssertComRC(rc);
+            delete pTask;
+            throw rc;
+        }
+
+        rc = startThread(pTask);
         if (FAILED(rc)) throw rc;
     }
@@ -2790,8 +2802,5 @@
     }
     else
-    {
-        /* return progress to the caller */
         progress.queryInterfaceTo(aProgress);
-    }
 
     LogFlowThisFunc(("LEAVE, rc=%Rhrc\n", rc));
@@ -4331,6 +4340,12 @@
 
     /* setup task object to carry out the operation asynchronously */
-    std::auto_ptr<Medium::Task> task(new DeleteTask(this, progress));
-    AssertComRCReturnRC(task->rc());
+    Medium::Task *pTask(new Medium::DeleteTask(this, progress));
+    rc = pTask->rc();
+    if (FAILED(rc))
+    {
+        AssertComRC(rc);
+        delete pTask;
+        return rc;
+    }
 
     if (aWait)
@@ -4339,9 +4354,10 @@
         m->state = MediumState_Deleting;
 
-        rc = runNow(task, NULL /* pfNeedsSaveSettings*/ );        // there is no save settings to do in taskThreadDelete()
+        rc = runNow(pTask, NULL /* pfNeedsSaveSettings*/ );        // there is no save settings to do in taskThreadDelete()
+        if (FAILED(rc)) return rc;
     }
     else
     {
-        rc = startThread(task);
+        rc = startThread(pTask);
         if (FAILED(rc)) return rc;
 
@@ -4351,8 +4367,5 @@
 
     if (aProgress != NULL)
-    {
-        /* return progress to the caller */
         *aProgress = progress;
-    }
 
     return rc;
@@ -4471,7 +4484,13 @@
 
     /* setup task object to carry out the operation asynchronously */
-    std::auto_ptr<Medium::Task> task(new CreateDiffTask(this, progress,
-                                                        aTarget, aVariant));
-    AssertComRCReturnRC(task->rc());
+    Medium::Task *pTask(new Medium::CreateDiffTask(this, progress, aTarget,
+                                                   aVariant));
+    rc = pTask->rc();
+    if (FAILED(rc))
+    {
+        AssertComRC(rc);
+        delete pTask;
+        return rc;
+    }
 
     /* register a task (it will deregister itself when done) */
@@ -4489,9 +4508,10 @@
         alock.release();
 
-        rc = runNow(task, pfNeedsSaveSettings);
+        rc = runNow(pTask, pfNeedsSaveSettings);
+        if (FAILED(rc)) return rc;
     }
     else
     {
-        rc = startThread(task);
+        rc = startThread(pTask);
         if (FAILED(rc)) return rc;
 
@@ -4501,8 +4521,5 @@
 
     if (aProgress != NULL)
-    {
-        /* return progress to the caller */
         *aProgress = progress;
-    }
 
     return rc;
@@ -4722,6 +4739,12 @@
 
     /* setup task object to carry out the operation asynchronously */
-    std::auto_ptr<Medium::Task> task(new MergeTask(this, progress, aChain));
-    AssertComRCReturnRC(task->rc());
+    Medium::Task *pTask(new Medium::MergeTask(this, progress, aChain));
+    rc = pTask->rc();
+    if (FAILED(rc))
+    {
+        AssertComRC(rc);
+        delete pTask;
+        return rc;
+    }
 
     /* Note: task owns aChain (will delete it when not needed) in all cases
@@ -4732,17 +4755,15 @@
     if (aWait)
     {
-        rc = runNow(task, pfNeedsSaveSettings);
+        rc = runNow(pTask, pfNeedsSaveSettings);
+        if (FAILED(rc)) return rc;
     }
     else
     {
-        rc = startThread(task);
+        rc = startThread(pTask);
         if (FAILED(rc)) return rc;
     }
 
     if (aProgress != NULL)
-    {
-        /* return progress to the caller */
         *aProgress = progress;
-    }
 
     return rc;
@@ -5019,8 +5040,4 @@
  * Starts a new thread driven by the appropriate Medium::Task::handler() method.
  *
- * @note if this method returns success, this Medium::Task object becomes owned
- *       by the started thread and will be automatically deleted when the
- *       thread terminates.
- *
  * @note When the task is executed by this method, IProgress::notifyComplete()
  *       is automatically called for the progress object associated with this
@@ -5028,13 +5045,18 @@
  *       other threads asynchronously waiting for it.
  */
-HRESULT Medium::startThread(std::auto_ptr<Medium::Task> task)
+HRESULT Medium::startThread(Medium::Task *pTask)
 {
     /// @todo use a more descriptive task name
-    int vrc = RTThreadCreate(NULL, Medium::Task::fntMediumTask, &task,
+    int vrc = RTThreadCreate(NULL, Medium::Task::fntMediumTask, pTask,
                              0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
                              "Medium::Task");
-    ComAssertMsgRCRet(vrc,
-                      ("Could not create Medium::Task thread (%Rrc)\n", vrc),
-                      E_FAIL);
+    if (RT_FAILURE(vrc))
+    {
+        delete pTask;
+        ComAssertMsgRCRet(vrc,
+                          ("Could not create Medium::Task thread (%Rrc)\n",
+                           vrc),
+                          E_FAIL);
+    }
 
     return S_OK;
@@ -5049,6 +5071,4 @@
  * operations are potentially lengthy and will block the calling thread in this
  * case.
- *
- * @note This Medium::Task object will be deleted when this method returns.
  *
  * @note When the task is executed by this method, IProgress::notifyComplete()
@@ -5058,11 +5078,11 @@
  *       complete the progress object in this case.
  */
-HRESULT Medium::runNow(std::auto_ptr<Medium::Task> task,
+HRESULT Medium::runNow(Medium::Task *pTask,
                        bool *pfNeedsSaveSettings)
 {
-    task->m_pfNeedsSaveSettings = pfNeedsSaveSettings;
+    pTask->m_pfNeedsSaveSettings = pfNeedsSaveSettings;
 
     /* NIL_RTTHREAD indicates synchronous call. */
-    return (HRESULT)Medium::Task::fntMediumTask(NIL_RTTHREAD, &task);
+    return (HRESULT)Medium::Task::fntMediumTask(NIL_RTTHREAD, pTask);
 }
 
@@ -5077,5 +5097,5 @@
  * @return
  */
-HRESULT Medium::taskThreadCreateBase(CreateBaseTask &task)
+HRESULT Medium::taskThreadCreateBase(Medium::CreateBaseTask &task)
 {
     HRESULT rc = S_OK;
@@ -5202,5 +5222,5 @@
  * @return
  */
-HRESULT Medium::taskThreadCreateDiff(CreateDiffTask &task)
+HRESULT Medium::taskThreadCreateDiff(Medium::CreateDiffTask &task)
 {
     HRESULT rc = S_OK;
@@ -5385,5 +5405,5 @@
  * @return
  */
-HRESULT Medium::taskThreadMerge(MergeTask &task)
+HRESULT Medium::taskThreadMerge(Medium::MergeTask &task)
 {
     HRESULT rc = S_OK;
@@ -5657,5 +5677,5 @@
  * @return
  */
-HRESULT Medium::taskThreadClone(CloneTask &task)
+HRESULT Medium::taskThreadClone(Medium::CloneTask &task)
 {
     HRESULT rc = S_OK;
@@ -5875,6 +5895,7 @@
  * @return
  */
-HRESULT Medium::taskThreadDelete(DeleteTask &task)
-{
+HRESULT Medium::taskThreadDelete(Medium::DeleteTask &task)
+{
+    NOREF(task);
     HRESULT rc = S_OK;
 
@@ -5940,5 +5961,5 @@
  * @return
  */
-HRESULT Medium::taskThreadReset(ResetTask &task)
+HRESULT Medium::taskThreadReset(Medium::ResetTask &task)
 {
     HRESULT rc = S_OK;
@@ -6050,5 +6071,5 @@
  * @return
  */
-HRESULT Medium::taskThreadCompact(CompactTask &task)
+HRESULT Medium::taskThreadCompact(Medium::CompactTask &task)
 {
     HRESULT rc = S_OK;
Index: /trunk/src/VBox/Main/include/MediumImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MediumImpl.h	(revision 27830)
+++ /trunk/src/VBox/Main/include/MediumImpl.h	(revision 27831)
@@ -318,14 +318,14 @@
     friend class MergeTask;
 
-    HRESULT startThread(std::auto_ptr<Task> task);
-    HRESULT runNow(std::auto_ptr<Task> task, bool *pfNeedsSaveSettings);
-
-    HRESULT taskThreadCreateBase(CreateBaseTask &task);
-    HRESULT taskThreadCreateDiff(CreateDiffTask &task);
-    HRESULT taskThreadMerge(MergeTask &task);
-    HRESULT taskThreadClone(CloneTask &task);
-    HRESULT taskThreadDelete(DeleteTask &task);
-    HRESULT taskThreadReset(ResetTask &task);
-    HRESULT taskThreadCompact(CompactTask &task);
+    HRESULT startThread(Medium::Task *pTask);
+    HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
+
+    HRESULT taskThreadCreateBase(Medium::CreateBaseTask &task);
+    HRESULT taskThreadCreateDiff(Medium::CreateDiffTask &task);
+    HRESULT taskThreadMerge(Medium::MergeTask &task);
+    HRESULT taskThreadClone(Medium::CloneTask &task);
+    HRESULT taskThreadDelete(Medium::DeleteTask &task);
+    HRESULT taskThreadReset(Medium::ResetTask &task);
+    HRESULT taskThreadCompact(Medium::CompactTask &task);
 
     struct Data;            // opaque data struct, defined in MediumImpl.cpp
