VirtualBox

Changeset 79968 in vbox


Ignore:
Timestamp:
Jul 25, 2019 1:28:23 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132399
Message:

Main/Medium::i_setLocation: Fixed leak in the error path where the desired and detected image type does not match. Some tidying up. bugref:9151

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r79965 r79968  
    825825    AutoCaller mParentCaller;
    826826};
     827
     828
     829
     830/**
     831 * Converts the Medium device type to the VD type.
     832 */
     833static const char *getVDTypeName(VDTYPE enmType)
     834{
     835    switch (enmType)
     836    {
     837        case VDTYPE_HDD:                return "HDD";
     838        case VDTYPE_OPTICAL_DISC:       return "DVD";
     839        case VDTYPE_FLOPPY:             return "floppy";
     840        case VDTYPE_INVALID:            return "invalid";
     841        default:
     842            AssertFailedReturn("unknown");
     843    }
     844}
     845
     846/**
     847 * Converts the Medium device type to the VD type.
     848 */
     849static const char *getDeviceTypeName(DeviceType_T enmType)
     850{
     851    switch (enmType)
     852    {
     853        case DeviceType_HardDisk:       return "HDD";
     854        case DeviceType_DVD:            return "DVD";
     855        case DeviceType_Floppy:         return "floppy";
     856        case DeviceType_Null:           return "null";
     857        case DeviceType_Network:        return "network";
     858        case DeviceType_USB:            return "USB";
     859        case DeviceType_SharedFolder:   return "shared folder";
     860        case DeviceType_Graphics3D:     return "graphics 3d";
     861        default:
     862            AssertFailedReturn("unknown");
     863    }
     864}
     865
    827866
    828867
     
    76197658        if (isImport)
    76207659        {
    7621             VDTYPE const enmDesiredType = m->devType == DeviceType_Floppy   ? VDTYPE_FLOPPY
    7622                                         : m->devType == DeviceType_DVD      ? VDTYPE_OPTICAL_DISC
    7623                                         : m->devType == DeviceType_HardDisk ? VDTYPE_HDD : VDTYPE_INVALID;
     7660            VDTYPE const enmDesiredType = i_convertDeviceType();
    76247661            VDTYPE enmType = VDTYPE_INVALID;
    76257662            char *backendName = NULL;
    76267663
    7627             int vrc = VINF_SUCCESS;
    7628 
    76297664            /* is it a file? */
    7630             {
    7631                 RTFILE file;
    7632                 vrc = RTFileOpen(&file, locationFull.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
    7633                 if (RT_SUCCESS(vrc))
    7634                     RTFileClose(file);
    7635             }
     7665            RTFILE hFile;
     7666            int vrc = RTFileOpen(&hFile, locationFull.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
    76367667            if (RT_SUCCESS(vrc))
    76377668            {
     7669                RTFileClose(hFile);
    76387670                vrc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
    76397671                                  locationFull.c_str(), enmDesiredType, &backendName, &enmType);
     
    76567688                                        tr("Permission problem accessing the file for the medium '%s' (%Rrc)"),
    76577689                                        locationFull.c_str(), vrc);
    7658                 else if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND)
     7690                if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND)
    76597691                    return setErrorBoth(VBOX_E_FILE_ERROR, vrc,
    76607692                                        tr("Could not find file for the medium '%s' (%Rrc)"),
    76617693                                        locationFull.c_str(), vrc);
    7662                 else if (aFormat.isEmpty())
     7694                if (aFormat.isEmpty())
    76637695                    return setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
    76647696                                        tr("Could not get the storage format of the medium '%s' (%Rrc)"),
    76657697                                        locationFull.c_str(), vrc);
    7666                 else
    7667                 {
    7668                     HRESULT rc = i_setFormat(aFormat);
    7669                     /* setFormat() must not fail since we've just used the backend so
    7670                      * the format object must be there */
    7671                     AssertComRCReturnRC(rc);
    7672                 }
     7698                HRESULT rc = i_setFormat(aFormat);
     7699                /* setFormat() must not fail since we've just used the backend so
     7700                         * the format object must be there */
     7701                AssertComRCReturnRC(rc);
    76737702            }
    76747703            else if (   enmType == VDTYPE_INVALID
     
    76797708                 * by the backend.
    76807709                 */
     7710                RTStrFree(backendName);
    76817711                return setError(E_FAIL,
    7682                                 tr("The medium '%s' can't be used as the requested device type"),
    7683                                 locationFull.c_str());
     7712                                tr("The medium '%s' can't be used as the requested device type (%s, detected %s)"),
     7713                                locationFull.c_str(), getDeviceTypeName(m->devType), getVDTypeName(enmType));
    76847714            }
    76857715            else
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