VirtualBox

Changeset 46613 in vbox for trunk/src/VBox/Storage/VDI.cpp


Ignore:
Timestamp:
Jun 18, 2013 10:27:13 AM (11 years ago)
Author:
vboxsync
Message:

Storage: Propagate errors when closing a file but free everything nevertheless (see @bugref{6791})

File:
1 edited

Legend:

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

    r46612 r46613  
    225225                vdiFlushImage(pImage);
    226226
    227             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     227            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    228228            pImage->pStorage = NULL;
    229229        }
     
    15061506
    15071507    /* Close the image. */
    1508     vdiFreeImage(pImage, false);
    1509 
    1510     /* Rename the file. */
    1511     rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
    1512     if (RT_FAILURE(rc))
    1513     {
    1514         /* The move failed, try to reopen the original image. */
    1515         int rc2 = vdiOpenImage(pImage, pImage->uOpenFlags);
    1516         if (RT_FAILURE(rc2))
    1517             rc = rc2;
    1518 
    1519         goto out;
    1520     }
    1521 
    1522     /* Update pImage with the new information. */
    1523     pImage->pszFilename = pszFilename;
    1524 
    1525     /* Open the new image. */
    1526     rc = vdiOpenImage(pImage, pImage->uOpenFlags);
    1527     if (RT_FAILURE(rc))
    1528         goto out;
     1508    rc = vdiFreeImage(pImage, false);
     1509    if (RT_SUCCESS(rc))
     1510    {
     1511        /* Rename the file. */
     1512        rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
     1513        if (RT_FAILURE(rc))
     1514        {
     1515            /* The move failed, try to reopen the original image. */
     1516            int rc2 = vdiOpenImage(pImage, pImage->uOpenFlags);
     1517            if (RT_FAILURE(rc2))
     1518                rc = rc2;
     1519
     1520            goto out;
     1521        }
     1522
     1523        /* Update pImage with the new information. */
     1524        pImage->pszFilename = pszFilename;
     1525
     1526        /* Open the new image. */
     1527        rc = vdiOpenImage(pImage, pImage->uOpenFlags);
     1528        if (RT_FAILURE(rc))
     1529            goto out;
     1530    }
    15291531
    15301532out:
     
    31653167
    31663168    if (pStorage)
    3167         vdIfIoIntFileClose(pIfIo, pStorage);
     3169    {
     3170        int rc2 = vdIfIoIntFileClose(pIfIo, pStorage);
     3171        if (RT_SUCCESS(rc))
     3172            rc = rc2; /* Propagate error code only if repairing was successful. */
     3173    }
    31683174
    31693175    LogFlowFunc(("returns %Rrc\n", rc));
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