VirtualBox

Changeset 17847 in vbox for trunk/src


Ignore:
Timestamp:
Mar 13, 2009 4:23:42 PM (16 years ago)
Author:
vboxsync
Message:

Storage/VMDK: put decompression buffer allocation in a place where the information is known, plug a few memory leaks in error situations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp

    r17775 r17847  
    12251225        RTMemTmpFree(pTmpGT);
    12261226
     1227        /* streamOptimized extents need a grain decompress buffer. */
     1228        pExtent->pvGrain = RTMemAlloc(VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));
     1229        if (!pExtent->pvGrain)
     1230        {
     1231            rc = VERR_NO_MEMORY;
     1232            goto out;
     1233        }
     1234
    12271235        if (uLastGrainSector)
    12281236        {
     
    13051313                                 &uGTSectorLE, sizeof(uGTSectorLE), NULL);
    13061314            if (RT_FAILURE(rc))
    1307                 return vmdkError(pExtent->pImage, rc, RT_SRC_POS, N_("VMDK: cannot write new redundant grain directory entry in '%s'"), pExtent->pszFullname);
     1315            {
     1316                rc = vmdkError(pExtent->pImage, rc, RT_SRC_POS, N_("VMDK: cannot write new redundant grain directory entry in '%s'"), pExtent->pszFullname);
     1317                goto out;
     1318            }
    13081319            uOffsetSectors += VMDK_BYTE2SECTOR(pExtent->cGTEntries * sizeof(uint32_t));
    13091320        }
     
    13191330                                 &uGTSectorLE, sizeof(uGTSectorLE), NULL);
    13201331            if (RT_FAILURE(rc))
    1321                 return vmdkError(pExtent->pImage, rc, RT_SRC_POS, N_("VMDK: cannot write new grain directory entry in '%s'"), pExtent->pszFullname);
     1332            {
     1333                rc = vmdkError(pExtent->pImage, rc, RT_SRC_POS, N_("VMDK: cannot write new grain directory entry in '%s'"), pExtent->pszFullname);
     1334                goto out;
     1335            }
    13221336            uOffsetSectors += VMDK_BYTE2SECTOR(pExtent->cGTEntries * sizeof(uint32_t));
    13231337        }
    13241338    }
    13251339    pExtent->cOverheadSectors = VMDK_BYTE2SECTOR(cbOverhead);
     1340
     1341    /* streamOptimized extents need a grain decompress buffer. */
     1342    if (pExtent->pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED)
     1343    {
     1344        pExtent->pvGrain = RTMemAlloc(VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));
     1345        if (!pExtent->pvGrain)
     1346        {
     1347            rc = VERR_NO_MEMORY;
     1348            goto out;
     1349        }
     1350    }
    13261351
    13271352out:
     
    25012526    }
    25022527
    2503     /* streamOptimized extents need a grain decryption buffer. */
    2504     if (pExtent->pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED)
    2505     {
    2506         pExtent->pvGrain = RTMemAlloc(VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));
    2507         if (!pExtent->pvGrain)
    2508         {
    2509             rc = VERR_NO_MEMORY;
    2510             goto out;
    2511         }
    2512         pExtent->uGrainSector = 0;
    2513     }
    2514 
    25152528out:
    25162529    if (RT_FAILURE(rc))
     
    27202733        RTStrFree((char *)(void *)pExtent->pszFullname);
    27212734        pExtent->pszFullname = NULL;
     2735    }
     2736    if (pExtent->pvGrain)
     2737    {
     2738        RTMemFree(pExtent->pvGrain);
     2739        pExtent->pvGrain = NULL;
    27222740    }
    27232741}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette