Index: /trunk/src/VBox/Main/MediumImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MediumImpl.cpp	(revision 23590)
+++ /trunk/src/VBox/Main/MediumImpl.cpp	(revision 23591)
@@ -95,4 +95,5 @@
           accessibleInLock(false),
           type(MediumType_Normal),
+          devType(DeviceType_HardDisk),
           logicalSize(0),
           hddOpenMode(OpenReadWrite),
@@ -128,4 +129,5 @@
 
     MediumType_T type;
+    DeviceType_T devType;
     uint64_t logicalSize;   /*< In MBytes. */
 
@@ -1047,5 +1049,5 @@
  * @param aVirtualBox   VirtualBox object.
  * @param aParent       Parent medium disk or NULL for a root (base) medium.
- * @param aType         Device type of the medium.
+ * @param aDeviceType   Device type of the medium.
  * @param aNode         Configuration settings.
  *
@@ -1054,5 +1056,5 @@
 HRESULT Medium::init(VirtualBox *aVirtualBox,
                      Medium *aParent,
-                     DeviceType_T aType,
+                     DeviceType_T aDeviceType,
                      const settings::Medium &data)
 {
@@ -1098,5 +1100,5 @@
 
     /* required */
-    if (aType == DeviceType_HardDisk)
+    if (aDeviceType == DeviceType_HardDisk)
     {
         AssertReturn(!data.strFormat.isEmpty(), E_FAIL);
@@ -1137,5 +1139,5 @@
     CheckComRCReturnRC(rc);
 
-    if (aType == DeviceType_HardDisk)
+    if (aDeviceType == DeviceType_HardDisk)
     {
         /* type is only for base hard disks */
@@ -1145,4 +1147,7 @@
     else
         m->type = MediumType_Writethrough;
+
+    /* remember device type for correct unregistering later */
+    m->devType = aDeviceType;
 
     LogFlowThisFunc(("m->locationFull='%ls', m->format=%ls, m->id={%RTuuid}\n",
@@ -1166,5 +1171,5 @@
         rc = pHD->init(aVirtualBox,
                        this,            // parent
-                       aType,
+                       aDeviceType,
                        m);              // child data
         CheckComRCBreakRC(rc);
@@ -1190,5 +1195,5 @@
  *
  * @param aVirtualBox   VirtualBox object.
- * @param aType         Device type of the medium.
+ * @param aDeviceType   Device type of the medium.
  * @param aLocation     Location of the host drive.
  * @param aDescription  Comment for this host drive.
@@ -1197,9 +1202,9 @@
  */
 HRESULT Medium::init(VirtualBox *aVirtualBox,
-                     DeviceType_T aType,
+                     DeviceType_T aDeviceType,
                      CBSTR aLocation,
                      CBSTR aDescription)
 {
-    ComAssertRet(aType == DeviceType_DVD || aType == DeviceType_Floppy, E_INVALIDARG);
+    ComAssertRet(aDeviceType == DeviceType_DVD || aDeviceType == DeviceType_Floppy, E_INVALIDARG);
     ComAssertRet(aLocation, E_INVALIDARG);
 
@@ -1215,5 +1220,5 @@
     RTUUID uuid;
     RTUuidClear(&uuid);
-    if (aType == DeviceType_DVD)
+    if (aDeviceType == DeviceType_DVD)
         memcpy(&uuid.au8[0], "DVD", 3);
     else
@@ -1229,4 +1234,5 @@
 
     m->type = MediumType_Writethrough;
+    m->devType = aDeviceType;
     m->state = MediumState_Created;
     m->hostDrive = true;
@@ -4690,5 +4696,19 @@
     }
 
-    HRESULT rc = mVirtualBox->unregisterHardDisk(this);
+    HRESULT rc = E_FAIL;
+    switch (m->devType)
+    {
+        case DeviceType_DVD:
+            rc = mVirtualBox->unregisterDVDImage(this);
+            break;
+        case DeviceType_Floppy:
+            rc = mVirtualBox->unregisterFloppyImage(this);
+            break;
+        case DeviceType_HardDisk:
+            rc = mVirtualBox->unregisterHardDisk(this);
+            break;
+        default:
+            break;
+    }
 
     if (FAILED(rc))
Index: /trunk/src/VBox/Main/include/MediumImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MediumImpl.h	(revision 23590)
+++ /trunk/src/VBox/Main/include/MediumImpl.h	(revision 23591)
@@ -88,9 +88,9 @@
     HRESULT init(VirtualBox *aVirtualBox,
                  Medium *aParent,
-                 DeviceType_T aType,
+                 DeviceType_T aDeviceType,
                  const settings::Medium &data);
     // initializer for host floppy/DVD
     HRESULT init(VirtualBox *aVirtualBox,
-                 DeviceType_T aType,
+                 DeviceType_T aDeviceType,
                  CBSTR aLocation,
                  CBSTR aDescription = NULL);
