VirtualBox

Changeset 40374 in vbox for trunk


Ignore:
Timestamp:
Mar 6, 2012 1:24:29 PM (13 years ago)
Author:
vboxsync
Message:

Runtime/checksum/manifest: potential memory leak

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/manifest.cpp

    r40329 r40374  
    451451    AssertReturn(cFiles > 0, VERR_INVALID_PARAMETER);
    452452
    453     /* Calculate the size necessary for the memory buffer. */
    454     size_t cbSize = 0;
    455     size_t cbMaxSize = 0;
    456     for (size_t i = 0; i < cFiles; ++i)
    457     {
    458         size_t cbTmp = strlen(RTPathFilename(paFiles[i].pszTestFile)) + strlen(paFiles[i].pszTestDigest) + 10;
    459         cbMaxSize = RT_MAX(cbMaxSize, cbTmp);
    460         cbSize += cbTmp;
    461     }
    462 
    463     /* Create the memory buffer */
    464     void *pvBuf = RTMemAlloc(cbSize);
    465     if (!pvBuf)
    466         return VERR_NO_MEMORY;
    467 
    468     /* Allocate a temporary string buffer. */
    469     char * pszTmp = RTStrAlloc(cbMaxSize + 1);
    470     size_t cbPos = 0;
    471453    const char *pcszDigestType;
    472454    switch (enmDigestType)
     
    479461        default: return VERR_INVALID_PARAMETER;
    480462    }
     463
     464    /* Calculate the size necessary for the memory buffer. */
     465    size_t cbSize = 0;
     466    size_t cbMaxSize = 0;
     467    for (size_t i = 0; i < cFiles; ++i)
     468    {
     469        size_t cbTmp = strlen(RTPathFilename(paFiles[i].pszTestFile)) + strlen(paFiles[i].pszTestDigest) + 10;
     470        cbMaxSize = RT_MAX(cbMaxSize, cbTmp);
     471        cbSize += cbTmp;
     472    }
     473
     474    /* Create the memory buffer */
     475    void *pvBuf = RTMemAlloc(cbSize);
     476    if (!pvBuf)
     477        return VERR_NO_MEMORY;
     478
     479    /* Allocate a temporary string buffer. */
     480    char *pszTmp = RTStrAlloc(cbMaxSize + 1);
     481    if (!pszTmp)
     482    {
     483        RTMemFree(pvBuf);
     484        return VERR_NO_MEMORY;
     485    }
     486    size_t cbPos = 0;
     487
    481488    for (size_t i = 0; i < cFiles; ++i)
    482489    {
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