Index: trunk/src/VBox/Storage/VD.cpp
===================================================================
--- trunk/src/VBox/Storage/VD.cpp	(revision 90815)
+++ trunk/src/VBox/Storage/VD.cpp	(revision 90816)
@@ -8512,7 +8512,33 @@
 VBOXDDU_DECL(uint64_t) VDGetSize(PVDISK pDisk, unsigned nImage)
 {
+    LogFlowFunc(("pDisk=%#p nImage=%u\n", pDisk, nImage));
+    /* sanity check */
+    AssertPtrReturn(pDisk, VERR_INVALID_POINTER);
+    AssertMsg(pDisk->u32Signature == VDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
+
+    /* Do the job. */
+    int rc2 = vdThreadStartRead(pDisk);
+    AssertRC(rc2);
+
+    uint64_t cbSize;
+    PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
+    AssertPtr(pImage);
+    if (pImage)
+        cbSize = vdImageGetSize(pImage);
+    else
+        cbSize = 0;
+
+    rc2 = vdThreadFinishRead(pDisk);
+    AssertRC(rc2);
+
+    LogFlowFunc(("returns %llu (%#RX64)\n", cbSize, cbSize));
+    return cbSize;
+}
+
+
+VBOXDDU_DECL(uint64_t) VDGetFileSize(PVDISK pDisk, unsigned nImage)
+{
     uint64_t cbSize;
     int rc2;
-    bool fLockRead = false;
 
     LogFlowFunc(("pDisk=%#p nImage=%u\n", pDisk, nImage));
@@ -8525,39 +8551,4 @@
         rc2 = vdThreadStartRead(pDisk);
         AssertRC(rc2);
-        fLockRead = true;
-
-        PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
-        AssertPtrBreakStmt(pImage, cbSize = 0);
-
-        cbSize = vdImageGetSize(pImage);
-    } while (0);
-
-    if (RT_UNLIKELY(fLockRead))
-    {
-        rc2 = vdThreadFinishRead(pDisk);
-        AssertRC(rc2);
-    }
-
-    LogFlowFunc(("returns %llu\n", cbSize));
-    return cbSize;
-}
-
-
-VBOXDDU_DECL(uint64_t) VDGetFileSize(PVDISK pDisk, unsigned nImage)
-{
-    uint64_t cbSize;
-    int rc2;
-    bool fLockRead = false;
-
-    LogFlowFunc(("pDisk=%#p nImage=%u\n", pDisk, nImage));
-    do
-    {
-        /* sanity check */
-        AssertPtrBreakStmt(pDisk, cbSize = 0);
-        AssertMsg(pDisk->u32Signature == VDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
-
-        rc2 = vdThreadStartRead(pDisk);
-        AssertRC(rc2);
-        fLockRead = true;
 
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
@@ -8566,9 +8557,6 @@
     } while (0);
 
-    if (RT_UNLIKELY(fLockRead))
-    {
-        rc2 = vdThreadFinishRead(pDisk);
-        AssertRC(rc2);
-    }
+    rc2 = vdThreadFinishRead(pDisk);
+    AssertRC(rc2);
 
     LogFlowFunc(("returns %llu\n", cbSize));
@@ -8582,5 +8570,4 @@
     int rc = VINF_SUCCESS;
     int rc2;
-    bool fLockRead = false;
 
     LogFlowFunc(("pDisk=%#p nImage=%u pPCHSGeometry=%#p\n",
@@ -8597,5 +8584,4 @@
         rc2 = vdThreadStartRead(pDisk);
         AssertRC(rc2);
-        fLockRead = true;
 
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
@@ -8615,9 +8601,6 @@
     } while (0);
 
-    if (RT_UNLIKELY(fLockRead))
-    {
-        rc2 = vdThreadFinishRead(pDisk);
-        AssertRC(rc2);
-    }
+    rc2 = vdThreadFinishRead(pDisk);
+    AssertRC(rc2);
 
     LogFlowFunc(("%Rrc (PCHS=%u/%u/%u)\n", rc,
@@ -8725,5 +8708,4 @@
     int rc = VINF_SUCCESS;
     int rc2;
-    bool fLockRead = false;
 
     LogFlowFunc(("pDisk=%#p nImage=%u pLCHSGeometry=%#p\n",
@@ -8738,8 +8720,6 @@
     do
     {
-
         rc2 = vdThreadStartRead(pDisk);
         AssertRC(rc2);
-        fLockRead = true;
 
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
@@ -8759,9 +8739,6 @@
     } while (0);
 
-    if (RT_UNLIKELY(fLockRead))
-    {
-        rc2 = vdThreadFinishRead(pDisk);
-        AssertRC(rc2);
-    }
+    rc2 = vdThreadFinishRead(pDisk);
+    AssertRC(rc2);
 
     LogFlowFunc((": %Rrc (LCHS=%u/%u/%u)\n", rc,
@@ -8870,5 +8847,4 @@
     int rc = VINF_SUCCESS;
     int rc2;
-    bool fLockRead = false;
 
     LogFlowFunc(("pDisk=%#p nImage=%u fFlags=%#x ppRegionList=%#p\n",
@@ -8885,5 +8861,4 @@
         rc2 = vdThreadStartRead(pDisk);
         AssertRC(rc2);
-        fLockRead = true;
 
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
@@ -8901,9 +8876,6 @@
     } while (0);
 
-    if (RT_UNLIKELY(fLockRead))
-    {
-        rc2 = vdThreadFinishRead(pDisk);
-        AssertRC(rc2);
-    }
+    rc2 = vdThreadFinishRead(pDisk);
+    AssertRC(rc2);
 
     LogFlowFunc((": %Rrc\n", rc));
@@ -8923,5 +8895,4 @@
     int rc = VINF_SUCCESS;
     int rc2;
-    bool fLockRead = false;
 
     LogFlowFunc(("pDisk=%#p nImage=%u puVersion=%#p\n",
@@ -8938,5 +8909,4 @@
         rc2 = vdThreadStartRead(pDisk);
         AssertRC(rc2);
-        fLockRead = true;
 
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
@@ -8946,9 +8916,6 @@
     } while (0);
 
-    if (RT_UNLIKELY(fLockRead)) /** @todo r=bird: This prediction is utter rubbish! Good example why avoid them... */
-    {
-        rc2 = vdThreadFinishRead(pDisk);
-        AssertRC(rc2);
-    }
+    rc2 = vdThreadFinishRead(pDisk);
+    AssertRC(rc2);
 
     LogFlowFunc(("returns %Rrc uVersion=%#x\n", rc, *puVersion));
@@ -9730,10 +9697,8 @@
     LogFlowFunc(("pszFilename=\"%s\"\n", pszFilename));
     /* Check arguments. */
-    AssertMsgReturn(VALID_PTR(pszFilename) && *pszFilename,
-                    ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
-                    VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
+    AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
     AssertPtrReturn(pszBackend, VERR_INVALID_POINTER);
-    AssertMsgReturn((fFlags & ~VD_REPAIR_FLAGS_MASK) == 0,
-                    ("fFlags=%#x\n", fFlags),
+    AssertMsgReturn((fFlags & ~VD_REPAIR_FLAGS_MASK) == 0, ("fFlags=%#x\n", fFlags),
                     VERR_INVALID_PARAMETER);
 
