VirtualBox

Changeset 107671 in vbox


Ignore:
Timestamp:
Jan 10, 2025 3:38:26 PM (2 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
166763
Message:

Storage/VMDK.cpp: Fix unused variable assignment (VERR_NO_MEMORY would get lost when allocating memory for the zero buffer fails) and replace allocating the buffer with using the zero 4K data object, bugref:3409

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VMDK.cpp

    r107654 r107671  
    4949#include <iprt/zip.h>
    5050#include <iprt/asm.h>
     51#include <iprt/zero.h>
    5152#ifdef RT_OS_WINDOWS
    5253# include <iprt/utf16.h>
     
    86538654    * of the image.
    86548655    */
    8655     void *pvBuf = NULL, *pvZero = NULL;
     8656    void *pvBuf = NULL;
     8657    AssertCompile(sizeof(g_abRTZero4K) >= VMDK_GRAIN_TABLE_SIZE);
    86568658
    86578659    do
     
    86618663        if (!pvBuf)
    86628664        {
    8663             rc = VERR_NO_MEMORY;
    8664             break;
    8665         }
    8666 
    8667         /* Allocate buffer for overwriting with zeroes. */
    8668         pvZero = RTMemAllocZ(VMDK_GRAIN_TABLE_SIZE);
    8669         if (!pvZero)
    8670         {
    8671             RTMemFree(pvBuf);
    8672             pvBuf = NULL;
    8673 
    86748665            rc = VERR_NO_MEMORY;
    86758666            break;
     
    87828773    }
    87838774
    8784     if (pvZero)
    8785     {
    8786         RTMemFree(pvZero);
    8787         pvZero = NULL;
    8788     }
    8789 
    87908775    pExtent->cGDEntries = cNewDirEntries;
    8791 
    8792     /* Allocate buffer for overwriting with zeroes. */
    8793     pvZero = RTMemAllocZ(VMDK_GRAIN_TABLE_SIZE);
    8794     if (!pvZero)
    8795         return VERR_NO_MEMORY;
    87968776
    87978777    // Allocate additional grain dir
     
    88168796
    88178797        rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pExtent->pFile->pStorage,
    8818                                     VMDK_SECTOR2BYTE(uTmpDirVal), pvZero,
     8798                                    VMDK_SECTOR2BYTE(uTmpDirVal), &g_abRTZero4K[0],
    88198799                                    VMDK_GRAIN_TABLE_SIZE);
    88208800
     
    88318811
    88328812        rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pExtent->pFile->pStorage,
    8833                                     VMDK_SECTOR2BYTE(uRTmpDirVal), pvZero,
     8813                                    VMDK_SECTOR2BYTE(uRTmpDirVal), &g_abRTZero4K[0],
    88348814                                    VMDK_GRAIN_TABLE_SIZE);
    88358815
     
    88398819        uRTmpDirVal += VMDK_GRAIN_DIR_ENTRY_SIZE;
    88408820    }
    8841 
    8842     RTMemFree(pvZero);
    8843     pvZero = NULL;
    88448821
    88458822    rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pExtent->pFile->pStorage,
Note: See TracChangeset for help on using the changeset viewer.

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