VirtualBox

Changeset 38718 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Sep 12, 2011 3:56:52 PM (13 years ago)
Author:
vboxsync
Message:

Main: Fix wrong medium attachment references after "Restore Snapshot" by making a depth copy of them

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

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

    r37824 r38718  
    6565struct MediumAttachment::Data
    6666{
    67     Data()
    68         : pMachine(NULL),
     67    Data(Machine * const aMachine = NULL)
     68        : pMachine(aMachine),
    6969          fIsEjected(false)
    7070    { }
     
    166166
    167167/**
     168 *  Initializes the medium attachment object given another guest object
     169 *  (a kind of copy constructor). This object makes a private copy of data
     170 *  of the original object passed as an argument.
     171 */
     172HRESULT MediumAttachment::initCopy(Machine *aParent, MediumAttachment *aThat)
     173{
     174    LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
     175
     176    ComAssertRet(aParent && aThat, E_INVALIDARG);
     177
     178    /* Enclose the state transition NotReady->InInit->Ready */
     179    AutoInitSpan autoInitSpan(this);
     180    AssertReturn(autoInitSpan.isOk(), E_FAIL);
     181
     182    m = new Data(aParent);
     183    /* m->pPeer is left null */
     184
     185    AutoCaller thatCaller(aThat);
     186    AssertComRCReturnRC(thatCaller.rc());
     187
     188    AutoReadLock thatlock(aThat COMMA_LOCKVAL_SRC_POS);
     189    m->bd.attachCopy(aThat->m->bd);
     190
     191    /* Confirm a successful initialization */
     192    autoInitSpan.setSucceeded();
     193
     194    return S_OK;
     195}
     196
     197/**
    168198 * Uninitializes the instance.
    169199 * Called from FinalRelease().
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r37985 r38718  
    18201820            setModified(IsModified_Storage);
    18211821            mMediaData.backup();
    1822             mMediaData->mAttachments = pSnapshotMachine->mMediaData->mAttachments;
     1822            mMediaData->mAttachments.clear();
     1823            for (MediaData::AttachmentList::const_iterator it = pSnapshotMachine->mMediaData->mAttachments.begin();
     1824                 it != pSnapshotMachine->mMediaData->mAttachments.end();
     1825                 ++it)
     1826            {
     1827                ComObjPtr<MediumAttachment> pAttach;
     1828                pAttach.createObject();
     1829                pAttach->initCopy(this, *it);
     1830                mMediaData->mAttachments.push_back(pAttach);
     1831            }
    18231832
    18241833            /* leave the locks before the potentially lengthy operation */
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