VirtualBox

Changeset 53323 in vbox


Ignore:
Timestamp:
Nov 13, 2014 2:52:50 PM (10 years ago)
Author:
vboxsync
Message:

Main/VirtualBox: take vbox lock before locking dhcp server list (#7500)

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r52596 r53323  
    338338    HRESULT i_registerDHCPServer(DHCPServer *aDHCPServer,
    339339                                 bool aSaveRegistry = true);
    340     HRESULT i_unregisterDHCPServer(DHCPServer *aDHCPServer,
    341                                    bool aSaveRegistry = true);
     340    HRESULT i_unregisterDHCPServer(DHCPServer *aDHCPServer);
    342341    HRESULT i_registerNATNetwork(NATNetwork *aNATNetwork,
    343342                                 bool aSaveRegistry = true);
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r52934 r53323  
    47854785    IDHCPServer *aP = aServer;
    47864786
    4787     HRESULT rc = i_unregisterDHCPServer(static_cast<DHCPServer *>(aP), true);
     4787    HRESULT rc = i_unregisterDHCPServer(static_cast<DHCPServer *>(aP));
    47884788
    47894789    return rc;
     
    48134813    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    48144814
     4815    // Acquire a lock on the VirtualBox object early to avoid lock order issues
     4816    // when we call i_saveSettings() later on.
     4817    AutoWriteLock vboxLock(this COMMA_LOCKVAL_SRC_POS);
    48154818    // need it below, in findDHCPServerByNetworkName (reading) and in
    48164819    // m->allDHCPServers.addChild, so need to get it here to avoid lock
     
    48354838
    48364839    m->allDHCPServers.addChild(aDHCPServer);
     4840    // we need to release the list lock before we attempt to acquire locks
     4841    // on other objects in i_saveSettings (see @bugref{7500})
     4842    alock.release();
    48374843
    48384844    if (aSaveSettings)
    48394845    {
    4840         AutoWriteLock vboxLock(this COMMA_LOCKVAL_SRC_POS);
     4846        // we acquired the lock on 'this' earlier to avoid lock order issues
    48414847        rc = i_saveSettings();
    4842         vboxLock.release();
    48434848
    48444849        if (FAILED(rc))
    4845             i_unregisterDHCPServer(aDHCPServer, false /* aSaveSettings */);
     4850        {
     4851            alock.acquire();
     4852            m->allDHCPServers.removeChild(aDHCPServer);
     4853        }
    48464854    }
    48474855
     
    48534861 *
    48544862 * @param aDHCPServer   DHCP server object to remove.
    4855  * @param aSaveSettings @c true to save settings to disk (default).
    4856  *
    4857  * When @a aSaveSettings is @c true, this operation may fail because of the
    4858  * failed #saveSettings() method it calls. In this case, the DHCP server
    4859  * will NOT be removed from the settingsi when this method returns.
     4863 *
     4864 * This operation may fail because of the failed #saveSettings() method it
     4865 * calls. In this case, the DHCP server will NOT be removed from the settings
     4866 * when this method returns.
    48604867 *
    48614868 * @note Locks this object for writing.
    48624869 */
    4863 HRESULT VirtualBox::i_unregisterDHCPServer(DHCPServer *aDHCPServer,
    4864                                            bool aSaveSettings /*= true*/)
     4870HRESULT VirtualBox::i_unregisterDHCPServer(DHCPServer *aDHCPServer)
    48654871{
    48664872    AssertReturn(aDHCPServer != NULL, E_INVALIDARG);
     
    48724878    AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc());
    48734879
     4880    AutoWriteLock vboxLock(this COMMA_LOCKVAL_SRC_POS);
     4881    AutoWriteLock alock(m->allDHCPServers.getLockHandle() COMMA_LOCKVAL_SRC_POS);
    48744882    m->allDHCPServers.removeChild(aDHCPServer);
    4875 
    4876     HRESULT rc = S_OK;
    4877 
    4878     if (aSaveSettings)
    4879     {
    4880         AutoWriteLock vboxLock(this COMMA_LOCKVAL_SRC_POS);
    4881         rc = i_saveSettings();
    4882         vboxLock.release();
    4883 
    4884         if (FAILED(rc))
    4885             rc = i_registerDHCPServer(aDHCPServer, false /* aSaveSettings */);
     4883    // we need to release the list lock before we attempt to acquire locks
     4884    // on other objects in i_saveSettings (see @bugref{7500})
     4885    alock.release();
     4886
     4887    HRESULT rc = i_saveSettings();
     4888
     4889    // undo the changes if we failed to save them
     4890    if (FAILED(rc))
     4891    {
     4892        alock.acquire();
     4893        m->allDHCPServers.addChild(aDHCPServer);
    48864894    }
    48874895
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette