VirtualBox

Changeset 72543 in vbox for trunk/src/VBox/Storage


Ignore:
Timestamp:
Jun 13, 2018 1:29:38 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123033
Message:

Storage: Fix plugin cleanup (especially the missing filter bits), and use #ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS more aggressively, letting the compiler detect sloppy code.

File:
1 edited

Legend:

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

    r69968 r72543  
    6464*********************************************************************************************************************************/
    6565
     66#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    6667/** Head of loaded plugin list. */
    6768static RTLISTANCHOR g_ListPluginsLoaded;
     69#endif
    6870
    6971/** Number of image backends supported. */
     
    7173/** Array of pointers to the image backends. */
    7274static PCVDIMAGEBACKEND *g_apBackends = NULL;
     75#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    7376/** Array of handles to the corresponding plugin. */
    7477static RTLDRMOD *g_ahBackendPlugins = NULL;
     78#endif
    7579/** Builtin image backends. */
    7680static PCVDIMAGEBACKEND aStaticBackends[] =
     
    9498/** Array of pointers to the cache backends. */
    9599static PCVDCACHEBACKEND *g_apCacheBackends = NULL;
     100#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    96101/** Array of handles to the corresponding plugin.
    97102 *
     
    99104 */
    100105static RTLDRMOD *g_ahCacheBackendPlugins = NULL;
     106#endif
    101107/** Builtin cache backends. */
    102108static PCVDCACHEBACKEND aStaticCacheBackends[] =
     
    136142        return VERR_NO_MEMORY;
    137143    g_apBackends = pTmp;
    138 
     144    memcpy(&g_apBackends[g_cBackends], ppBackends, cBackends * sizeof(PCVDIMAGEBACKEND));
     145
     146#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    139147    RTLDRMOD *pTmpPlugins = (RTLDRMOD*)RTMemRealloc(g_ahBackendPlugins,
    140148           (g_cBackends + cBackends) * sizeof(RTLDRMOD));
     
    142150        return VERR_NO_MEMORY;
    143151    g_ahBackendPlugins = pTmpPlugins;
    144     memcpy(&g_apBackends[g_cBackends], ppBackends, cBackends * sizeof(PCVDIMAGEBACKEND));
    145152    for (unsigned i = g_cBackends; i < g_cBackends + cBackends; i++)
    146153        g_ahBackendPlugins[i] = hPlugin;
     154#else
     155    RT_NOREF(hPlugin);
     156#endif
     157
    147158    g_cBackends += cBackends;
    148159    return VINF_SUCCESS;
     
    168179        return VERR_NO_MEMORY;
    169180    g_apCacheBackends = pTmp;
    170 
     181    memcpy(&g_apCacheBackends[g_cCacheBackends], ppBackends, cBackends * sizeof(PCVDCACHEBACKEND));
     182
     183#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    171184    RTLDRMOD *pTmpPlugins = (RTLDRMOD*)RTMemReallocTag(g_ahCacheBackendPlugins,
    172185                                                       (g_cCacheBackends + cBackends) * sizeof(RTLDRMOD),
     
    175188        return VERR_NO_MEMORY;
    176189    g_ahCacheBackendPlugins = pTmpPlugins;
    177     memcpy(&g_apCacheBackends[g_cCacheBackends], ppBackends, cBackends * sizeof(PCVDCACHEBACKEND));
    178190    for (unsigned i = g_cCacheBackends; i < g_cCacheBackends + cBackends; i++)
    179191        g_ahCacheBackendPlugins[i] = hPlugin;
     192#else
     193    RT_NOREF(hPlugin);
     194#endif
     195
    180196    g_cCacheBackends += cBackends;
    181197    return VINF_SUCCESS;
     
    227243    g_apFilterBackends = pTmp;
    228244
     245#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    229246    PRTLDRMOD pTmpPlugins = (PRTLDRMOD)RTMemRealloc(g_pahFilterBackendPlugins,
    230247                                                    (g_cFilterBackends + cBackends) * sizeof(RTLDRMOD));
     
    236253    for (unsigned i = g_cFilterBackends; i < g_cFilterBackends + cBackends; i++)
    237254        g_pahFilterBackendPlugins[i] = hPlugin;
     255#else
     256    RT_NOREF(hPlugin);
     257#endif
     258
    238259    g_cFilterBackends += cBackends;
    239260    return VINF_SUCCESS;
     
    719740}
    720741
     742#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    721743/**
    722744 * internal: scans plugin directory and loads found plugins.
     
    724746static int vdLoadDynamicBackends(void)
    725747{
    726 #ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    727748    /*
    728749     * Enumerate plugin backends from the application directory where the other
     
    735756
    736757    return vdPluginLoadFromPath(szPath);
    737 #else
    738     return VINF_SUCCESS;
    739 #endif
    740 }
     758}
     759#endif
    741760
    742761/**
     
    854873    {
    855874        rc = vdAddCacheBackends(NIL_RTLDRMOD, aStaticCacheBackends, RT_ELEMENTS(aStaticCacheBackends));
     875#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    856876        if (RT_SUCCESS(rc))
    857877        {
     
    859879            rc = vdLoadDynamicBackends();
    860880        }
     881#endif
    861882    }
    862883
     
    875896        return VERR_INTERNAL_ERROR;
    876897
     898#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
     899    if (g_pahFilterBackendPlugins)
     900        RTMemFree(g_pahFilterBackendPlugins);
     901#endif
     902    if (g_apFilterBackends)
     903        RTMemFree(g_apFilterBackends);
     904#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    877905    if (g_ahCacheBackendPlugins)
    878906        RTMemFree(g_ahCacheBackendPlugins);
     907#endif
    879908    if (g_apCacheBackends)
    880909        RTMemFree(g_apCacheBackends);
     
    887916    g_cCacheBackends = 0;
    888917    g_apCacheBackends = NULL;
     918#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
    889919    g_ahCacheBackendPlugins = NULL;
     920#endif
     921
     922    /* Clear the supported filter backends. */
     923    g_cFilterBackends = 0;
     924    g_apFilterBackends = NULL;
     925#ifndef VBOX_HDD_NO_DYNAMIC_BACKENDS
     926    g_pahFilterBackendPlugins = NULL;
     927#endif
    890928
    891929#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