Index: /trunk/src/VBox/Main/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MachineImpl.cpp	(revision 30930)
+++ /trunk/src/VBox/Main/MachineImpl.cpp	(revision 30931)
@@ -6021,4 +6021,9 @@
     if (fCloseMedia)
     {
+        // call backup before iterating over the media, because backup WILL change
+        // the pointers and invalidate iterators (grrrrr)
+        setModified(IsModified_Storage);
+        mMediaData.backup();         // do not call this or iterators will be invalidated
+
         // caller wants automatic detachment: then do that and report all media to the array
         MediaData::AttachmentList::iterator it = mMediaData->mAttachments.begin();
@@ -6030,7 +6035,4 @@
             if (!pMedium.isNull())
                 llMedia.push_back(pMedium);
-
-            setModified(IsModified_Storage);
-            mMediaData.backup();
 
             // for non-hard disk media, detach straight away
@@ -6039,7 +6041,7 @@
                 pMedium->detachFrom(mData->mUuid);
 
-            // remove this attachment; erase() returns the iterator of the next element
+            // remove this attachment; erase() returns the iterator behind the thing that got deleted
             it = mMediaData->mAttachments.erase(it);
-        }
+        };
     }
     else
Index: /trunk/src/VBox/Main/testcase/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Main/testcase/Makefile.kmk	(revision 30930)
+++ /trunk/src/VBox/Main/testcase/Makefile.kmk	(revision 30931)
@@ -93,4 +93,5 @@
 	ovf-dummy.vmdk \
 	ovf-joomla-0.9/joomla-1.1.4-ovf.ovf=>ovf-joomla-0.9/joomla-1.1.4-ovf.ovf \
+	ovf-winhost-audio-nodisks/WinXP.ovf=>ovf-winhost-audio-nodisks/WinXP.ovf \
 	ovf-winxp-vbox-sharedfolders/winxp.ovf=>ovf-winxp-vbox-sharedfolders/winxp.ovf
 endif
Index: /trunk/src/VBox/Main/testcase/tstOVF.cpp
===================================================================
--- /trunk/src/VBox/Main/testcase/tstOVF.cpp	(revision 30930)
+++ /trunk/src/VBox/Main/testcase/tstOVF.cpp	(revision 30931)
@@ -309,4 +309,9 @@
         EventQueue eventQ;
 
+        // for each testcase, we will copy the dummy VMDK image to the subdirectory with the OVF testcase
+        // so that the import will find the disks it expects; this is just for testing the import since
+        // the imported machines will obviously not be usable.
+        // llFiles2Delete receives the paths of all the files that we need to clean up later.
+
         // testcase 1: import ovf-joomla-0.9/joomla-1.1.4-ovf.ovf
         copyDummyDiskImage("joomla-0.9", llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
@@ -318,4 +323,7 @@
         copyDummyDiskImage("winxp-vbox-sharedfolders", llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk");
         importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf", llMachinesCreated);
+
+        // testcase 3: import ovf-winxp-vbox-sharedfolders/winxp.ovf
+        importOVF("winhost-audio-nodisks", pVirtualBox, "ovf-testcases/ovf-winhost-audio-nodisks/WinXP.ovf", llMachinesCreated);
 
         RTPrintf("Machine imports done, no errors. Cleaning up...\n");
