Index: /trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
===================================================================
--- /trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp	(revision 32883)
+++ /trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp	(revision 32884)
@@ -1200,4 +1200,5 @@
 static int vmdkAllocGrainDirectory(PVMDKIMAGE pImage, PVMDKEXTENT pExtent)
 {
+    int rc = VINF_SUCCESS;
     size_t cbGD = pExtent->cGDEntries * sizeof(uint32_t);
     uint32_t *pGD = NULL, *pRGD = NULL;
@@ -1262,5 +1263,5 @@
 
     rc = vmdkAllocGrainDirectory(pImage, pExtent);
-    if (RT_FAILED(rc))
+    if (RT_FAILURE(rc))
         goto out;
 
@@ -1269,5 +1270,5 @@
     rc = vmdkFileReadSync(pImage, pExtent->pFile,
                           VMDK_SECTOR2BYTE(pExtent->uSectorGD),
-                          pGD, cbGD, NULL);
+                          pExtent->pGD, cbGD, NULL);
     AssertRC(rc);
     if (RT_FAILURE(rc))
@@ -1276,15 +1277,14 @@
         goto out;
     }
-    for (i = 0, pGDTmp = pGD; i < pExtent->cGDEntries; i++, pGDTmp++)
+    for (i = 0, pGDTmp = pExtent->pGD; i < pExtent->cGDEntries; i++, pGDTmp++)
         *pGDTmp = RT_LE2H_U32(*pGDTmp);
 
     if (pExtent->uSectorRGD)
     {
-        pExtent->pRGD = pRGD;
         /* The VMDK 1.1 spec seems to talk about compressed grain directories,
          * but in reality they are not compressed. */
         rc = vmdkFileReadSync(pImage, pExtent->pFile,
                               VMDK_SECTOR2BYTE(pExtent->uSectorRGD),
-                              pRGD, cbGD, NULL);
+                              pExtent->pRGD, cbGD, NULL);
         AssertRC(rc);
         if (RT_FAILURE(rc))
@@ -1293,5 +1293,5 @@
             goto out;
         }
-        for (i = 0, pRGDTmp = pRGD; i < pExtent->cGDEntries; i++, pRGDTmp++)
+        for (i = 0, pRGDTmp = pExtent->pRGD; i < pExtent->cGDEntries; i++, pRGDTmp++)
             *pRGDTmp = RT_LE2H_U32(*pRGDTmp);
 
@@ -1312,5 +1312,5 @@
         }
 
-        for (i = 0, pGDTmp = pGD, pRGDTmp = pRGD;
+        for (i = 0, pGDTmp = pExtent->pGD, pRGDTmp = pExtent->pRGD;
              i < pExtent->cGDEntries;
              i++, pGDTmp++, pRGDTmp++)
@@ -1379,5 +1379,5 @@
             goto out;
         }
-        for (i = 0, pGDTmp = pGD; i < pExtent->cGDEntries; i++, pGDTmp++)
+        for (i = 0, pGDTmp = pExtent->pGD; i < pExtent->cGDEntries; i++, pGDTmp++)
         {
             /* If no grain table is allocated skip the entry. */
@@ -1498,5 +1498,5 @@
 
     rc = vmdkAllocGrainDirectory(pImage, pExtent);
-    if (RT_FAILED(rc))
+    if (RT_FAILURE(rc))
         goto out;
 
@@ -1506,10 +1506,10 @@
         uint64_t uOffsetSectors;
 
-        if (pRGD)
+        if (pExtent->pRGD)
         {
             uOffsetSectors = pExtent->uSectorRGD + VMDK_BYTE2SECTOR(cbGDRounded);
             for (i = 0; i < pExtent->cGDEntries; i++)
             {
-                pRGD[i] = uOffsetSectors;
+                pExtent->pRGD[i] = uOffsetSectors;
                 uGTSectorLE = RT_H2LE_U64(uOffsetSectors);
                 /* Write the redundant grain directory entry to disk. */
@@ -1529,5 +1529,5 @@
         for (i = 0; i < pExtent->cGDEntries; i++)
         {
-            pGD[i] = uOffsetSectors;
+            pExtent->pGD[i] = uOffsetSectors;
             uGTSectorLE = RT_H2LE_U64(uOffsetSectors);
             /* Write the grain directory entry to disk. */
