Index: trunk/src/VBox/Main/DVDDriveImpl.cpp
===================================================================
--- trunk/src/VBox/Main/DVDDriveImpl.cpp	(revision 18193)
+++ trunk/src/VBox/Main/DVDDriveImpl.cpp	(revision 18194)
@@ -590,4 +590,16 @@
 
         m.rollback();
+        if (!m->image.isNull())
+        {
+            /* Reattach from the old image. */
+            HRESULT rc = m->image->attachTo(mParent->id(), mParent->snapshotId());
+            AssertComRC (rc);
+            if (Global::IsOnline (adep.machineState()))
+            {
+                /* Lock from the old image. */
+                rc = m->image->LockRead (NULL);
+                AssertComRC (rc);
+            }
+        }
     }
 
@@ -609,8 +621,4 @@
     AssertComRCReturnVoid (peerCaller.rc());
 
-    /* we need adep for the state check */
-    Machine::AutoAnyStateDependency adep (mParent);
-    AssertComRCReturnVoid (adep.rc());
-
     /* lock both for writing since we modify both (mPeer is "master" so locked
      * first) */
@@ -619,20 +627,4 @@
     if (m.isBackedUp())
     {
-        Data *oldData = m.backedUpData();
-
-        if (!oldData->image.isNull() &&
-            !oldData->image.equalsTo (m->image))
-        {
-            /* detach the old image that will go away after commit */
-            oldData->image->detachFrom (mParent->id(), mParent->snapshotId());
-
-            /* unlock the image for reading if the VM is online */
-            if (Global::IsOnline (adep.machineState()))
-            {
-                HRESULT rc = oldData->image->UnlockRead (NULL);
-                AssertComRC (rc);
-            }
-        }
-
         m.commit();
         if (mPeer)
@@ -676,4 +668,19 @@
 {
     AssertReturn (isWriteLockOnCurrentThread(), E_FAIL);
+
+    /* we need adep for the state check */
+    Machine::AutoAnyStateDependency adep (mParent);
+    AssertComRCReturn (adep.rc(), false);
+
+    if (!m->image.isNull())
+    {
+        HRESULT rc = m->image->detachFrom (mParent->id(), mParent->snapshotId());
+        AssertComRC (rc);
+        if (Global::IsOnline (adep.machineState()))
+        {
+            rc = m->image->UnlockRead (NULL);
+            AssertComRC (rc);
+        }
+    }
 
     m.backup();
Index: trunk/src/VBox/Main/FloppyDriveImpl.cpp
===================================================================
--- trunk/src/VBox/Main/FloppyDriveImpl.cpp	(revision 18193)
+++ trunk/src/VBox/Main/FloppyDriveImpl.cpp	(revision 18194)
@@ -597,4 +597,16 @@
 
         m.rollback();
+        if (!m->image.isNull())
+        {
+            /* Reattach from the old image. */
+            HRESULT rc = m->image->attachTo(mParent->id(), mParent->snapshotId());
+            AssertComRC (rc);
+            if (Global::IsOnline (adep.machineState()))
+            {
+                /* Lock from the old image. */
+                rc = m->image->LockRead (NULL);
+                AssertComRC (rc);
+            }
+        }
     }
 
@@ -616,8 +628,4 @@
     AssertComRCReturnVoid (peerCaller.rc());
 
-    /* we need adep for the state check */
-    Machine::AutoAnyStateDependency adep (mParent);
-    AssertComRCReturnVoid (adep.rc());
-
     /* lock both for writing since we modify both (mPeer is "master" so locked
      * first) */
@@ -626,20 +634,4 @@
     if (m.isBackedUp())
     {
-        Data *oldData = m.backedUpData();
-
-        if (!oldData->image.isNull() &&
-            !oldData->image.equalsTo (m->image))
-        {
-            /* detach the old image that will go away after commit */
-            oldData->image->detachFrom (mParent->id(), mParent->snapshotId());
-
-            /* unlock the image for reading if the VM is online */
-            if (Global::IsOnline (adep.machineState()))
-            {
-                HRESULT rc = oldData->image->UnlockRead (NULL);
-                AssertComRC (rc);
-            }
-        }
-
         m.commit();
         if (mPeer)
@@ -681,4 +673,19 @@
 {
     AssertReturn (isWriteLockOnCurrentThread(), E_FAIL);
+
+    /* we need adep for the state check */
+    Machine::AutoAnyStateDependency adep (mParent);
+    AssertComRCReturn (adep.rc(), false);
+
+    if (!m->image.isNull())
+    {
+        HRESULT rc = m->image->detachFrom (mParent->id(), mParent->snapshotId());
+        AssertComRC (rc);
+        if (Global::IsOnline (adep.machineState()))
+        {
+            rc = m->image->UnlockRead (NULL);
+            AssertComRC (rc);
+        }
+    }
 
     m.backup();
