Index: /trunk/src/VBox/Main/include/MachineImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MachineImpl.h	(revision 37776)
+++ /trunk/src/VBox/Main/include/MachineImpl.h	(revision 37777)
@@ -827,5 +827,4 @@
                          GuidList *pllRegistriesThatNeedSaving);
 
-    HRESULT searchAndAddImplicitParents(ComObjPtr<Medium> p, MediaList &llMedia) const;
     HRESULT detachAllMedia(AutoWriteLock &writeLock,
                            Snapshot *pSnapshot,
Index: /trunk/src/VBox/Main/src-server/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 37776)
+++ /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 37777)
@@ -9652,41 +9652,4 @@
 
 /**
- * Search for medias which are not attached to any machine, but in the chain to
- * an attached disk. Mediums are only consided if they are:
- * - have only one child
- * - no refereneces to any machines
- * - are of normal medium type
- *
- * This is done recursive and the recursing is stopped if a medium has more the
- * one child or there is no parent anymore.
- *
- * Used in detachAllMedia.
- *
- * @param pMedium   Medium to investigate.
- * @param llMedia   Caller's list to add a corrosponding media to.
- * @return
- */
-HRESULT Machine::searchAndAddImplicitParents(ComObjPtr<Medium> pMedium, MediaList &llMedia) const
-{
-    if (!pMedium.isNull())
-    {
-        AutoCaller mac(pMedium);
-        if (FAILED(mac.rc())) return mac.rc();
-        AutoReadLock lock(pMedium COMMA_LOCKVAL_SRC_POS);
-        MediaList childs = pMedium->getChildren();
-        if (childs.size() == 1)
-        {
-            if (   pMedium->getMachineBackRefCount() == 0
-                && pMedium->getType() == MediumType_Normal
-                && find(llMedia.begin(), llMedia.end(), pMedium) == llMedia.end())
-                llMedia.push_back(pMedium);
-            /* Recurse */
-            return searchAndAddImplicitParents(pMedium->getParent(), llMedia);
-        }
-    }
-    return S_OK;
-}
-
-/**
  * Goes thru all media of the given list and
  *
@@ -9734,4 +9697,7 @@
         if (!pMedium.isNull())
         {
+            AutoCaller mac(pMedium);
+            if (FAILED(mac.rc())) return mac.rc();
+            AutoReadLock lock(pMedium COMMA_LOCKVAL_SRC_POS);
             DeviceType_T devType = pMedium->getDeviceType();
             if (    (    cleanupMode == CleanupMode_DetachAllReturnHardDisksOnly
@@ -9741,9 +9707,28 @@
             {
                 llMedia.push_back(pMedium);
-                /* not enabled yet
-                rc = searchAndAddImplicitParents(pMedium->getParent(), llMedia);
-                if (FAILED(rc))
-                    return rc;
-                */
+                ComObjPtr<Medium> pParent = pMedium->getParent();
+                /*
+                 * Search for medias which are not attached to any machine, but
+                 * in the chain to an attached disk. Mediums are only consided
+                 * if they are:
+                 * - have only one child
+                 * - no references to any machines
+                 * - are of normal medium type
+                 */
+                while (!pParent.isNull())
+                {
+                    AutoCaller mac1(pParent);
+                    if (FAILED(mac1.rc())) return mac1.rc();
+                    AutoReadLock lock1(pParent COMMA_LOCKVAL_SRC_POS);
+                    if (pParent->getChildren().size() == 1)
+                    {
+                        if (   pParent->getMachineBackRefCount() == 0
+                            && pParent->getType() == MediumType_Normal
+                            && find(llMedia.begin(), llMedia.end(), pParent) == llMedia.end())
+                            llMedia.push_back(pParent);
+                    }else
+                        break;
+                    pParent = pParent->getParent();
+                }
             }
         }
