VirtualBox

Changeset 92144 in vbox for trunk/src


Ignore:
Timestamp:
Oct 29, 2021 12:58:11 PM (3 years ago)
Author:
vboxsync
Message:

Main/VirtualBoxClient: take some more care when processing the VBoxEventType_OnLanguageChanged callback as we might be racing com::Shutdown and having the ground open up beneath our feet at any time. Logging. bugref:1909

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp

    r91718 r92144  
    4040#endif
    4141
     42#include <new>
     43
    4244
    4345/** Waiting time between probing whether VBoxSVC is alive. */
     
    8486            case VBoxEventType_OnLanguageChanged:
    8587            {
     88                /*
     89                 * Proceed with uttmost care as we might be racing com::Shutdown()
     90                 * and have the ground open up beneath us.
     91                 */
     92                LogFunc(("VBoxEventType_OnLanguageChanged\n"));
    8693                VirtualBoxTranslator *pTranslator = VirtualBoxTranslator::tryInstance();
    8794                if (pTranslator)
    8895                {
    8996                    ComPtr<ILanguageChangedEvent> pEvent = aEvent;
    90                     HRESULT rc = E_FAIL;
    9197                    Assert(pEvent);
    9298
     99                    /* This call may fail if we're racing COM shutdown. */
    93100                    com::Bstr bstrLanguageId;
    94                     rc = pEvent->COMGETTER(LanguageId)(bstrLanguageId.asOutParam());
    95                     AssertComRC(rc);
    96 
    97                     com::Utf8Str strLanguageId(bstrLanguageId);
    98                     pTranslator->i_loadLanguage(strLanguageId.c_str());
     101                    HRESULT hrc = pEvent->COMGETTER(LanguageId)(bstrLanguageId.asOutParam());
     102                    if (SUCCEEDED(hrc))
     103                    {
     104                        try
     105                        {
     106                            com::Utf8Str strLanguageId(bstrLanguageId);
     107                            LogFunc(("New language ID: %s\n", strLanguageId.c_str()));
     108                            pTranslator->i_loadLanguage(strLanguageId.c_str());
     109                        }
     110                        catch (std::bad_alloc &)
     111                        {
     112                            LogFunc(("Caught bad_alloc"));
     113                        }
     114                    }
     115                    else
     116                        LogFunc(("Failed to get new language ID: %Rhrc\n", hrc));
     117
    99118                    pTranslator->release();
    100119                }
     
    560579    AutoUninitSpan autoUninitSpan(this);
    561580    if (autoUninitSpan.uninitDone())
     581    {
     582        LogFlowThisFunc(("already done\n"));
    562583        return;
     584    }
    563585
    564586#ifdef VBOX_WITH_MAIN_NLS
     
    589611
    590612    ASMAtomicDecU32(&g_cInstances);
     613
     614    LogFlowThisFunc(("returns\n"));
    591615}
    592616
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