VirtualBox

Changeset 92039 in vbox for trunk


Ignore:
Timestamp:
Oct 25, 2021 2:27:59 PM (3 years ago)
Author:
vboxsync
Message:

Main: bugref:1909: Fixed memory leak in the translation engine

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/VirtualBoxTranslator.cpp

    r91718 r92039  
    3737RTCRITSECTRW                VirtualBoxTranslator::s_instanceRwLock;
    3838VirtualBoxTranslator       *VirtualBoxTranslator::s_pInstance = NULL;
     39static RTONCE               g_tlsOnce = RTONCE_INITIALIZER;
    3940static RTTLS                g_idxTls = NIL_RTTLS;
    4041
     
    6162        delete pCache;
    6263    }
     64}
     65
     66
     67/**
     68 * @callback_method_impl{FNRTONCECLEANUP, Destroys TLS index during the process termination.}
     69 */
     70DECLCALLBACK(void) uninitTls(void *pvUser, bool fLazyCleanUpOk)
     71{
     72    RT_NOREF(pvUser);
     73    if (fLazyCleanUpOk && g_idxTls != NIL_RTTLS)
     74    {
     75        RTTlsFree(g_idxTls);
     76        g_idxTls = NIL_RTTLS;
     77    }
     78}
     79
     80
     81/**
     82 * @callback_method_impl{FNRTONCE}
     83 */
     84static DECLCALLBACK(int32_t) initTls(void *pvUser)
     85{
     86    RT_NOREF(pvUser);
     87    RTTlsAllocEx(&g_idxTls, &freeThreadCache);
     88    return VINF_SUCCESS;
    6389}
    6490
     
    7197    , m_hStrCache(NIL_RTSTRCACHE)
    7298{
    73     RTTlsAllocEx(&g_idxTls, &freeThreadCache);
    7499    int rc = RTStrCacheCreate(&m_hStrCache, "API Translation");
    75100    m_rcCache = rc;
     
    90115            RTTlsSet(g_idxTls, NULL);
    91116        }
    92         RTTlsFree(g_idxTls);
    93         g_idxTls = NIL_RTTLS;
    94117    }
    95118
     
    446469static LastTranslation *getTlsEntry() RT_NOEXCEPT
    447470{
    448     if (RT_LIKELY(g_idxTls != NIL_RTTLS))
     471    int rc = RTOnceEx(&g_tlsOnce, initTls, uninitTls, NULL);
     472    if (RT_SUCCESS(rc) && RT_LIKELY(g_idxTls != NIL_RTTLS))
    449473    {
    450474        LastTranslation *pEntry = (LastTranslation *)RTTlsGet(g_idxTls);
     
    457481            pEntry = new LastTranslation();
    458482            pEntry->first = pEntry->second = "";
    459             int rc = RTTlsSet(g_idxTls, pEntry);
     483            rc = RTTlsSet(g_idxTls, pEntry);
    460484            if (RT_SUCCESS(rc))
    461485                return pEntry;
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