VirtualBox

Changeset 69968 in vbox


Ignore:
Timestamp:
Dec 7, 2017 10:54:35 AM (7 years ago)
Author:
vboxsync
Message:

VDPlugin: Free g_ahCacheBackendPlugins on shutdown; don't use memcpy to shuffle array members, use memmov.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VDPlugin.cpp

    r69753 r69968  
    9494/** Array of pointers to the cache backends. */
    9595static PCVDCACHEBACKEND *g_apCacheBackends = NULL;
    96 /** Array of handles to the corresponding plugin. */
     96/** Array of handles to the corresponding plugin.
     97 *
     98 * @todo r=bird: This looks rather pointless.
     99 */
    97100static RTLDRMOD *g_ahCacheBackendPlugins = NULL;
    98101/** Builtin cache backends. */
     
    159162static int vdAddCacheBackends(RTLDRMOD hPlugin, PCVDCACHEBACKEND *ppBackends, unsigned cBackends)
    160163{
    161     PCVDCACHEBACKEND *pTmp = (PCVDCACHEBACKEND*)RTMemRealloc(g_apCacheBackends,
    162            (g_cCacheBackends + cBackends) * sizeof(PCVDCACHEBACKEND));
     164    PCVDCACHEBACKEND *pTmp = (PCVDCACHEBACKEND*)RTMemReallocTag(g_apCacheBackends,
     165                                                                (g_cCacheBackends + cBackends) * sizeof(PCVDCACHEBACKEND),
     166                                                                "may-leak:vdAddCacheBackend");
    163167    if (RT_UNLIKELY(!pTmp))
    164168        return VERR_NO_MEMORY;
    165169    g_apCacheBackends = pTmp;
    166170
    167     RTLDRMOD *pTmpPlugins = (RTLDRMOD*)RTMemRealloc(g_ahCacheBackendPlugins,
    168            (g_cCacheBackends + cBackends) * sizeof(RTLDRMOD));
     171    RTLDRMOD *pTmpPlugins = (RTLDRMOD*)RTMemReallocTag(g_ahCacheBackendPlugins,
     172                                                       (g_cCacheBackends + cBackends) * sizeof(RTLDRMOD),
     173                                                       "may-leak:vdAddCacheBackend");
    169174    if (RT_UNLIKELY(!pTmpPlugins))
    170175        return VERR_NO_MEMORY;
     
    370375        while (i < g_cBackends && g_ahBackendPlugins[i] == pIt->hPlugin)
    371376        {
    372             memcpy(&g_apBackends[i], &g_apBackends[i + 1], (g_cBackends - i - 1) * sizeof(PCVDIMAGEBACKEND));
    373             memcpy(&g_ahBackendPlugins[i], &g_ahBackendPlugins[i + 1], (g_cBackends - i - 1) * sizeof(RTLDRMOD));
     377            memmove(&g_apBackends[i], &g_apBackends[i + 1], (g_cBackends - i - 1) * sizeof(PCVDIMAGEBACKEND));
     378            memmove(&g_ahBackendPlugins[i], &g_ahBackendPlugins[i + 1], (g_cBackends - i - 1) * sizeof(RTLDRMOD));
    374379            /** @todo for now skip reallocating, doesn't save much */
    375380            g_cBackends--;
     
    380385        while (i < g_cCacheBackends && g_ahCacheBackendPlugins[i] == pIt->hPlugin)
    381386        {
    382             memcpy(&g_apCacheBackends[i], &g_apCacheBackends[i + 1], (g_cCacheBackends - i - 1) * sizeof(PCVDCACHEBACKEND));
    383             memcpy(&g_ahCacheBackendPlugins[i], &g_ahCacheBackendPlugins[i + 1], (g_cCacheBackends - i - 1) * sizeof(RTLDRMOD));
     387            memmove(&g_apCacheBackends[i], &g_apCacheBackends[i + 1], (g_cCacheBackends - i - 1) * sizeof(PCVDCACHEBACKEND));
     388            memmove(&g_ahCacheBackendPlugins[i], &g_ahCacheBackendPlugins[i + 1], (g_cCacheBackends - i - 1) * sizeof(RTLDRMOD));
    384389            /** @todo for now skip reallocating, doesn't save much */
    385390            g_cCacheBackends--;
     
    390395        while (i < g_cFilterBackends && g_pahFilterBackendPlugins[i] == pIt->hPlugin)
    391396        {
    392             memcpy(&g_apFilterBackends[i], &g_apFilterBackends[i + 1], (g_cFilterBackends - i - 1) * sizeof(PCVDFILTERBACKEND));
    393             memcpy(&g_pahFilterBackendPlugins[i], &g_pahFilterBackendPlugins[i + 1], (g_cFilterBackends - i - 1) * sizeof(RTLDRMOD));
     397            memmove(&g_apFilterBackends[i], &g_apFilterBackends[i + 1], (g_cFilterBackends - i - 1) * sizeof(PCVDFILTERBACKEND));
     398            memmove(&g_pahFilterBackendPlugins[i], &g_pahFilterBackendPlugins[i + 1], (g_cFilterBackends - i - 1) * sizeof(RTLDRMOD));
    394399            /** @todo for now skip reallocating, doesn't save much */
    395400            g_cFilterBackends--;
     
    870875        return VERR_INTERNAL_ERROR;
    871876
     877    if (g_ahCacheBackendPlugins)
     878        RTMemFree(g_ahCacheBackendPlugins);
    872879    if (g_apCacheBackends)
    873880        RTMemFree(g_apCacheBackends);
     
    880887    g_cCacheBackends = 0;
    881888    g_apCacheBackends = NULL;
     889    g_ahCacheBackendPlugins = NULL;
    882890
    883891#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
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