Index: trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 78748)
+++ trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 78749)
@@ -1019,5 +1019,14 @@
 
     /* Create the progress object */
-    pProgress.createObject();
+    try
+    {
+        rc = pProgress.createObject();
+        if (FAILED(rc))
+            return rc;
+    }
+    catch (std::bad_alloc &)
+    {
+        return E_OUTOFMEMORY;
+    }
 
     // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
@@ -1026,9 +1035,7 @@
     m->ulWeightForManifestOperation = 0;
 
-    ULONG cOperations;
+    ULONG cOperations = 1               // one for XML setup
+                      + m->cDisks;      // plus one per disk
     ULONG ulTotalOperationsWeight;
-
-    cOperations =   1               // one for XML setup
-                  + m->cDisks;      // plus one per disk
     if (m->ulTotalDisksMB)
     {
@@ -1064,5 +1071,5 @@
         case ImportS3:
         {
-            cOperations += 1 + 1;     // another one for the manifest file & another one for the import
+            cOperations += 1 + 1;       // another one for the manifest file & another one for the import
             ulTotalOperationsWeight = m->ulTotalDisksMB;
             if (!m->ulTotalDisksMB)
@@ -1081,5 +1088,5 @@
         case WriteS3:
         {
-            cOperations += 1 + 1;     // another one for the mf & another one for temporary creation
+            cOperations += 1 + 1;       // another one for the mf & another one for temporary creation
 
             if (m->ulTotalDisksMB)
@@ -1110,12 +1117,11 @@
          m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
 
-    rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
-                         Bstr(strDescription).raw(),
-                         TRUE /* aCancelable */,
-                         cOperations, // ULONG cOperations,
-                         ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
-                         Bstr(strDescription).raw(), // CBSTR bstrFirstOperationDescription,
-                         m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
-    return rc;
+    return pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
+                           strDescription,
+                           TRUE /* aCancelable */,
+                           cOperations, // ULONG cOperations,
+                           ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
+                           strDescription, // CBSTR bstrFirstOperationDescription,
+                           m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
 }
 
Index: trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 78748)
+++ trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 78749)
@@ -782,8 +782,13 @@
     if (aOptions.size())
     {
-        m->optListImport.setCapacity(aOptions.size());
-        for (size_t i = 0; i < aOptions.size(); ++i)
-        {
-            m->optListImport.insert(i, aOptions[i]);
+        try
+        {
+            m->optListImport.setCapacity(aOptions.size());
+            for (size_t i = 0; i < aOptions.size(); ++i)
+                m->optListImport.insert(i, aOptions[i]);
+        }
+        catch (std::bad_alloc &)
+        {
+            return E_OUTOFMEMORY;
         }
     }
@@ -803,19 +808,9 @@
 
     ComObjPtr<Progress> progress;
-    HRESULT rc = S_OK;
-    try
-    {
-        rc = i_importImpl(m->locInfo, progress);
-    }
-    catch (HRESULT aRC)
-    {
-        rc = aRC;
-    }
-
-    if (SUCCEEDED(rc))
-        /* Return progress to the caller */
+    HRESULT hrc = i_importImpl(m->locInfo, progress);
+    if (SUCCEEDED(hrc))
         progress.queryInterfaceTo(aProgress.asOutParam());
 
-    return rc;
+    return hrc;
 }
 
@@ -2818,94 +2813,84 @@
                                 ComObjPtr<Progress> &progress)
 {
-    HRESULT rc = S_OK;
-
-    SetUpProgressMode mode;
-    if (locInfo.storageType == VFSType_File)
-        mode = ImportFile;
-    else if (locInfo.storageType == VFSType_Cloud)
-        mode = ImportCloud;
+    HRESULT rc;
+
+    /* Initialize our worker task */
+    ThreadTask *pTask;
+    if (locInfo.storageType != VFSType_Cloud)
+    {
+        rc = i_setUpProgress(progress, Utf8StrFmt(tr("Importing appliance '%s'"), locInfo.strPath.c_str()),
+                             locInfo.storageType == VFSType_File ? ImportFile : ImportS3);
+        if (FAILED(rc))
+            return setError(rc, tr("Failed to create task for importing appliance into VirtualBox"));
+        try
+        {
+            pTask = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
+        }
+        catch (std::bad_alloc &)
+        {
+            return E_OUTOFMEMORY;
+        }
+    }
     else
-        mode = ImportS3;
-
-    /* Initialize our worker task */
-    TaskOVF* ovfTask = NULL;
-    TaskCloud* cloudTask = NULL;
-    try
-    {
-        if (mode == ImportFile)
-        {
-            rc = i_setUpProgress(progress,
-                                 BstrFmt(tr("Importing appliance '%s'"), locInfo.strPath.c_str()),
-                                 mode);
-            if (FAILED(rc)) throw rc;
-
-            ovfTask = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
-            rc = ovfTask->createThread();
-        }
-        else if (mode == ImportCloud)
-        {
-            progress.createObject();
-            if (locInfo.strProvider.equals("OCI"))
-            {
-                /*
-                 * 1. Create a custom image from the instance
-                 *  - 2 operations (starting and waiting)
-                 * 2. Import the custom image into the Object Storage (OCI format - TAR file with QCOW2 image and JSON file)
-                 *  - 2 operations (starting and waiting)
-                 * 3. Download the object from the Object Storage
-                 *  - 2 operations (starting and waiting)
-                 * 4. Open the object, extract QCOW2 image and convert one QCOW2->VDI
-                 *  - 1 operation (extracting and conversion are piped)
-                 * 5. Create VM with user settings and attach the converted image to VM
-                 *  - 1 operation.
-                 *  sum up = 2+2+2+1+1 = 8 op
-                */
-
-                /*
-                 * See src/VBox/ExtPacks/Puel/OCI/OCICloudClient.h.
-                 * Weight of cloud import operations (1-3 items from above):
-                 * Total = 750 = 10+40+50+50+200x2+200.
-                 *
-                 * Weight of local import operations (4-5 items from above):
-                 * Total = 250 = 200 (extract and convert) + 50 (create VM, attach disks)
-                 */
-                progress->init(mVirtualBox, static_cast<IAppliance*>(this),
-                             Bstr("Importing VM from Cloud...").raw(),
-                             TRUE /* aCancelable */,
-                             8, // ULONG cOperations,
-                             1000, // ULONG ulTotalOperationsWeight,
-                             Bstr("Importing VM from Cloud...").raw(), // aFirstOperationDescription
-                             10); // ULONG ulFirstOperationWeight
-            }
-            else
-                return setErrorVrc(VBOX_E_NOT_SUPPORTED,
-                                   tr("Only \"OCI\" cloud provider is supported for now. \"%s\" isn't supported."),
-                                   locInfo.strProvider.c_str());
-
-            cloudTask = new TaskCloud(this, TaskCloud::Import, locInfo, progress);
-            rc = cloudTask->createThread();
-            if (FAILED(rc)) throw rc;
-        }
-    }
-    catch (HRESULT aRc)
-    {
-        rc = aRc;
-    }
-    catch (...)
-    {
-        rc = setError(VBOX_E_OBJECT_NOT_FOUND,
-                            tr("Could not create a task object for importing appliance into VirtualBox"));
-    }
-
-    if (FAILED(rc))
-    {
-        if (ovfTask)
-            delete ovfTask;
-        if (cloudTask)
-            delete cloudTask;
-        throw rc;
-    }
-
-    return rc;
+    {
+        if (locInfo.strProvider.equals("OCI"))
+        {
+            /*
+             * 1. Create a custom image from the instance:
+             *    - 2 operations (starting and waiting)
+             * 2. Import the custom image into the Object Storage (OCI format - TAR file with QCOW2 image and JSON file):
+             *    - 2 operations (starting and waiting)
+             * 3. Download the object from the Object Storage:
+             *    - 2 operations (starting and waiting)
+             * 4. Open the object, extract QCOW2 image and convert one QCOW2->VDI:
+             *    - 1 operation (extracting and conversion are piped)
+             * 5. Create VM with user settings and attach the converted image to VM:
+             *    - 1 operation.
+             *
+             * Total: 2+2+2+1+1 = 8 operations
+             *
+             * See src/VBox/ExtPacks/Puel/OCI/OCICloudClient.h.
+             * Weight of cloud import operations (1-3 items from above):
+             * Total = 750 = 10+40+50+50+200x2+200.
+             *
+             * Weight of local import operations (4-5 items from above):
+             * Total = 250 = 200 (extract and convert) + 50 (create VM, attach disks)
+             */
+            try
+            {
+                rc = progress.createObject();
+                if (SUCCEEDED(rc))
+                    rc = progress->init(mVirtualBox, static_cast<IAppliance *>(this),
+                                        Utf8Str(tr("Importing VM from Cloud...")),
+                                        TRUE /* aCancelable */,
+                                        8, // ULONG cOperations,
+                                        1000, // ULONG ulTotalOperationsWeight,
+                                        Utf8Str(tr("Importing VM from Cloud...")), // aFirstOperationDescription
+                                        10); // ULONG ulFirstOperationWeight
+                if (SUCCEEDED(rc))
+                    pTask = new TaskCloud(this, TaskCloud::Import, locInfo, progress);
+                else
+                    pTask = NULL; /* shut up vcc */
+            }
+            catch (std::bad_alloc &)
+            {
+                return E_OUTOFMEMORY;
+            }
+            if (FAILED(rc))
+                return setError(rc, tr("Failed to create task for importing appliance into VirtualBox"));
+        }
+        else
+            return setError(E_NOTIMPL, tr("Only \"OCI\" cloud provider is supported for now. \"%s\" isn't supported."),
+                            locInfo.strProvider.c_str());
+    }
+
+    /*
+     * Start the task thread.
+     */
+    rc = pTask->createThread();
+    pTask = NULL;
+    if (SUCCEEDED(rc))
+        return rc;
+    return setError(rc, tr("Failed to start thread for importing appliance into VirtualBox"));
 }
 
