VirtualBox

Changeset 13340 in vbox


Ignore:
Timestamp:
Oct 16, 2008 1:16:33 PM (16 years ago)
Author:
vboxsync
Message:

#3230: Memory leaks fixed in VHD backend

Location:
trunk/src/VBox/Devices/Storage
Files:
2 edited

Legend:

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

    r12762 r13340  
    802802}
    803803
     804static void vhdFreeImageMemory(PVHDIMAGE pImage)
     805{
     806    if (pImage->pszParentFilename)
     807    {
     808        RTStrFree(pImage->pszParentFilename);
     809        pImage->pszParentFilename = NULL;
     810    }
     811    if (pImage->pBlockAllocationTable)
     812    {
     813        RTMemFree(pImage->pBlockAllocationTable);
     814        pImage->pBlockAllocationTable = NULL;
     815    }
     816    if (pImage->pu8Bitmap)
     817    {
     818        RTMemFree(pImage->pu8Bitmap);
     819        pImage->pu8Bitmap = NULL;
     820    }
     821    RTMemFree(pImage);
     822}
     823
    804824static int vhdFreeImage(PVHDIMAGE pImage)
    805825{
     
    811831        vhdFlush(pImage);
    812832        RTFileClose(pImage->File);
    813         RTMemFree(pImage);
     833        vhdFreeImageMemory(pImage);
    814834    }
    815835
     
    826846     * not signalled as an error. After all nothing bad happens. */
    827847    if (pImage) {
    828         if (pImage->pu8Bitmap)
    829         {
    830             RTMemFree(pImage->pu8Bitmap);
    831             pImage->pu8Bitmap = NULL;
    832         }
    833848        if (fDelete)
    834849        {
     
    836851            RTFileClose(pImage->File);
    837852            RTFileDelete(pImage->pszFilename);
     853            vhdFreeImageMemory(pImage);
    838854        }
    839855        else
    840856            rc = vhdFreeImage(pImage);
    841         if (pImage->pszParentFilename)
    842             RTStrFree(pImage->pszParentFilename);
    843857    }
    844858
     
    898912            uint32_t cSectors = 0;
    899913            uint32_t iBitmap = cBATEntryIndex / 8; /* Byte in the block bitmap. */
     914            Assert(iBitmap < pImage->cbDataBlockBitmap);
    900915
    901916            /*
     
    11091124        if (pImage->fDynHdrNeedsUpdate)
    11101125            vhdDynamicHeaderUpdate(pImage);
     1126        RTMemFree(pBlockAllocationTableToWrite);
    11111127    }
    11121128
  • trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp

    r13295 r13340  
    635635        if (VBOX_FAILURE(rc)) \
    636636        { \
     637            if (pvBuf) \
     638                RTMemFree(pvBuf); \
    637639            VDDestroy(pVD); \
    638640            return rc; \
    639641        } \
    640642    } while (0)
     643
     644    void *pvBuf = RTMemAlloc(_1M);
    641645
    642646    /* Create error interface. */
     
    672676    PSEGMENT paSegments  = (PSEGMENT)RTMemAllocZ(sizeof(struct Segment) * (nSegments + 1));
    673677
    674     void *pvBuf = RTMemAlloc(_1M);
    675 
    676678    RNDCTX ctx;
    677679    initializeRandomGenerator(&ctx, u32Seed);
     
    692694
    693695    VDDestroy(pVD);
     696    if (pvBuf)
     697        RTMemFree(pvBuf);
    694698#undef CHECK
    695699    return 0;
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