Index: /trunk/src/VBox/Main/MediumImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MediumImpl.cpp	(revision 35138)
+++ /trunk/src/VBox/Main/MediumImpl.cpp	(revision 35139)
@@ -1747,8 +1747,9 @@
     m->type = aType;
 
-    // save the global settings; for that we should hold only the VirtualBox lock
+    // save the settings
+    GuidList llRegistriesThatNeedSaving;
+    addToRegistryIDList(llRegistriesThatNeedSaving);
     mlock.release();
-    AutoWriteLock alock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-    HRESULT rc = m->pVirtualBox->saveSettings();
+    HRESULT rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
 
     return rc;
@@ -1870,16 +1871,20 @@
                         m->strLocationFull.c_str());
 
+    HRESULT rc = S_OK;
+
     if (m->autoReset != !!aAutoReset)
     {
         m->autoReset = !!aAutoReset;
 
-        // save the global settings; for that we should hold only the VirtualBox lock
+        // save the settings
+        GuidList llRegistriesThatNeedSaving;
+        addToRegistryIDList(llRegistriesThatNeedSaving);
         mlock.release();
-        AutoWriteLock alock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-        return m->pVirtualBox->saveSettings();
-    }
-
-    return S_OK;
-}
+        rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
+    }
+
+    return rc;
+}
+
 STDMETHODIMP Medium::COMGETTER(LastAccessError)(BSTR *aLastAccessError)
 {
@@ -2300,8 +2305,9 @@
     it->second = aValue;
 
-    // save the global settings; for that we should hold only the VirtualBox lock
+    // save the settings
+    GuidList llRegistriesThatNeedSaving;
+    addToRegistryIDList(llRegistriesThatNeedSaving);
     mlock.release();
-    AutoWriteLock alock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-    HRESULT rc = m->pVirtualBox->saveSettings();
+    HRESULT rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
 
     return rc;
@@ -2377,9 +2383,9 @@
     }
 
+    // save the settings
+    GuidList llRegistriesThatNeedSaving;
+    addToRegistryIDList(llRegistriesThatNeedSaving);
     mlock.release();
-
-    // saveSettings needs vbox lock
-    AutoWriteLock alock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-    HRESULT rc = m->pVirtualBox->saveSettings();
+    HRESULT rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
 
     return rc;
@@ -6604,7 +6610,7 @@
     {
         // in asynchronous mode, save settings now
-        // for that we should hold only the VirtualBox lock
-        AutoWriteLock vboxlock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-        m->pVirtualBox->saveSettings();
+        GuidList llRegistriesThatNeedSaving;
+        addToRegistryIDList(llRegistriesThatNeedSaving);
+        rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
     }
     else
@@ -6869,6 +6875,8 @@
     // now, at the end of this task (always asynchronous), save the settings
     {
-        AutoWriteLock vboxlock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-        m->pVirtualBox->saveSettings();
+        // save the settings
+        GuidList llRegistriesThatNeedSaving;
+        addToRegistryIDList(llRegistriesThatNeedSaving);
+        rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
     }
 
@@ -7623,6 +7631,8 @@
     // now, at the end of this task (always asynchronous), save the settings
     {
-        AutoWriteLock vboxlock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
-        m->pVirtualBox->saveSettings();
+        // save the settings
+        GuidList llRegistriesThatNeedSaving;
+        addToRegistryIDList(llRegistriesThatNeedSaving);
+        rc = m->pVirtualBox->saveRegistries(llRegistriesThatNeedSaving);
     }
 
Index: /trunk/src/VBox/Main/VirtualBoxImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 35138)
+++ /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 35139)
@@ -3732,4 +3732,15 @@
 }
 
+/**
+ * Saves all settings files according to the given list of UUIDs, which are
+ * either machine IDs (in which case Machine::saveSettings is invoked) or
+ * the global registry UUID (in which case VirtualBox::saveSettings is invoked).
+ *
+ * This locks machines and the VirtualBox object as necessary, so better not
+ * hold any locks before calling this.
+ *
+ * @param llRegistriesThatNeedSaving
+ * @return
+ */
 HRESULT VirtualBox::saveRegistries(const GuidList &llRegistriesThatNeedSaving)
 {
