Index: /trunk/src/VBox/Main/glue/string.cpp
===================================================================
--- /trunk/src/VBox/Main/glue/string.cpp	(revision 55941)
+++ /trunk/src/VBox/Main/glue/string.cpp	(revision 55942)
@@ -51,24 +51,22 @@
     size_t cwc;
     int vrc = ::RTStrCalcUtf16LenEx(a_pszSrc, a_cchMax, &cwc);
-    if (RT_FAILURE(vrc))
-    {
-        /* ASSUME: input is valid Utf-8. Fake out of memory error. */
+    if (RT_SUCCESS(vrc))
+    {
+        m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR)));
+        if (RT_LIKELY(m_bstr))
+        {
+            PRTUTF16 pwsz = (PRTUTF16)m_bstr;
+            vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL);
+            if (RT_SUCCESS(vrc))
+                return;
+
+            /* This should not happen! */
+            AssertRC(vrc);
+            cleanup();
+        }
+    }
+    else /* ASSUME: input is valid Utf-8. Fake out of memory error. */
         AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTStrNLen(a_pszSrc, a_cchMax), a_pszSrc));
-        throw std::bad_alloc();
-    }
-
-    m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR)));
-    if (RT_UNLIKELY(!m_bstr))
-        throw std::bad_alloc();
-
-    PRTUTF16 pwsz = (PRTUTF16)m_bstr;
-    vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL);
-    if (RT_FAILURE(vrc))
-    {
-        /* This should not happen! */
-        AssertRC(vrc);
-        cleanup();
-        throw std::bad_alloc();
-    }
+    throw std::bad_alloc();
 }
 
@@ -81,8 +79,9 @@
 {
     size_t cb = length() + 1;
-    *pstr = (char*)nsMemory::Alloc(cb);
-    if (RT_UNLIKELY(!*pstr))
+    *pstr = (char *)nsMemory::Alloc(cb);
+    if (RT_LIKELY(*pstr))
+        memcpy(*pstr, c_str(), cb);
+    else
         throw std::bad_alloc();
-    memcpy(*pstr, c_str(), cb);
 }
 
@@ -90,9 +89,11 @@
 {
     size_t cb = length() + 1;
-    *pstr = (char*)nsMemory::Alloc(cb);
-    if (RT_UNLIKELY(!*pstr))
-        return E_OUTOFMEMORY;
-    memcpy(*pstr, c_str(), cb);
-    return S_OK;
+    *pstr = (char *)nsMemory::Alloc(cb);
+    if (RT_LIKELY(*pstr))
+    {
+        memcpy(*pstr, c_str(), cb);
+        return S_OK;
+    }
+    return E_OUTOFMEMORY;
 }
 #endif
