VirtualBox

Changeset 5523 in vbox for trunk


Ignore:
Timestamp:
Oct 26, 2007 5:28:37 PM (17 years ago)
Author:
vboxsync
Message:

Main: Fixed memory errors and leaks found by valgrind.

Location:
trunk/src/VBox
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxBFE/USBProxyService.cpp

    r4071 r5523  
    302302}
    303303
     304/*static*/ void USBProxyService::freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs)
     305{
     306    while (cIfs-- > 0)
     307    {
     308        RTMemFree (pIf->paEndpoints);
     309        pIf->paEndpoints = NULL;
     310        RTStrFree ((char *)pIf->pszDriver);
     311        pIf->pszDriver = NULL;
     312        RTStrFree ((char *)pIf->pszInterface);
     313        pIf->pszInterface = NULL;
     314
     315        freeInterfaceMembers(pIf->paAlts, pIf->cAlts);
     316        RTMemFree(pIf->paAlts);
     317        pIf->paAlts = NULL;
     318        pIf->cAlts = 0;
     319
     320        /* next */
     321        pIf++;
     322    }
     323}
    304324
    305325/*static*/ void USBProxyService::freeDevice (PUSBDEVICE pDevice)
     
    309329    while (cCfgs-- > 0)
    310330    {
    311         PUSBINTERFACE pIf = pCfg->paInterfaces;
    312         unsigned cIfs = pCfg->bNumInterfaces;
    313         while (cIfs-- > 0)
    314         {
    315             RTMemFree (pIf->paEndpoints);
    316             pIf->paEndpoints = NULL;
    317             RTStrFree ((char *)pIf->pszDriver);
    318             pIf->pszDriver = NULL;
    319             RTStrFree ((char *)pIf->pszInterface);
    320             pIf->pszInterface = NULL;
    321             /* next */
    322             pIf++;
    323         }
     331        freeInterfaceMembers (pCfg->paInterfaces, pCfg->bNumInterfaces);
    324332        RTMemFree (pCfg->paInterfaces);
    325333        pCfg->paInterfaces = NULL;
     334        pCfg->bNumInterfaces = 0;
     335
    326336        RTStrFree ((char *)pCfg->pszConfiguration);
    327337        pCfg->pszConfiguration = NULL;
  • trunk/src/VBox/Frontends/VBoxBFE/USBProxyService.h

    r4071 r5523  
    136136
    137137public:
     138    /**
     139     * Free all the members of a USB interface returned by getDevice().
     140     *
     141     * @param   pIf         Pointer to the interface.
     142     * @param   cIfs        Number of consecutive interfaces pIf points to
     143     */
     144    static void freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs);
     145
    138146    /**
    139147     * Free one USB device returned by getDevice().
  • trunk/src/VBox/Frontends/VBoxBFE/USBProxyServiceLinux.cpp

    r4071 r5523  
    840840                {
    841841                    USBINTERFACE If = {0};
     842                    bool fIfAdopted = false;
    842843                    while (*psz && VBOX_SUCCESS (rc))
    843844                    {
     
    883884                                    Assert (!If.bInterfaceNumber); Assert (!If.bAlternateSetting);
    884885                                    *pIf = If;
     886                                    fIfAdopted = true;
    885887                                }
    886888                                else
     
    895897                                pIf = &pCfg->paInterfaces[If.bInterfaceNumber];
    896898                                if (!If.bAlternateSetting)
     899                                {
     900                                    freeInterfaceMembers (pIf, 1);
    897901                                    *pIf = If;
     902                                    fIfAdopted = true;
     903                                }
    898904                                else
    899905                                {
     
    902908                                    {
    903909                                        pIf->paAlts = paAlts;
    904                                         pIf = &paAlts[pIf->cAlts++];
     910                                        // don't do pIf = &paAlts[pIf->cAlts++]; as it will increment after the assignment
     911                                        unsigned cAlts = pIf->cAlts++;
     912                                        pIf = &paAlts[cAlts];
    905913                                        *pIf = If;
     914                                        fIfAdopted = true;
    906915                                    }
    907916                                    else
     
    916925                        }
    917926                    }
     927
     928                    if (!fIfAdopted)
     929                        freeInterfaceMembers (&If, 1);
    918930
    919931                    /* start anew with endpoints. */
  • trunk/src/VBox/Main/USBProxyService.cpp

    r4071 r5523  
    384384
    385385
     386/*static*/ void USBProxyService::freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs)
     387{
     388    while (cIfs-- > 0)
     389    {
     390        RTMemFree (pIf->paEndpoints);
     391        pIf->paEndpoints = NULL;
     392        RTStrFree ((char *)pIf->pszDriver);
     393        pIf->pszDriver = NULL;
     394        RTStrFree ((char *)pIf->pszInterface);
     395        pIf->pszInterface = NULL;
     396
     397        freeInterfaceMembers(pIf->paAlts, pIf->cAlts);
     398        RTMemFree(pIf->paAlts);
     399        pIf->paAlts = NULL;
     400        pIf->cAlts = 0;
     401
     402        /* next */
     403        pIf++;
     404    }
     405}
     406
    386407/*static*/ void USBProxyService::freeDeviceMembers (PUSBDEVICE pDevice)
    387408{
     
    390411    while (cCfgs-- > 0)
    391412    {
    392         PUSBINTERFACE pIf = pCfg->paInterfaces;
    393         unsigned cIfs = pCfg->bNumInterfaces;
    394         while (cIfs-- > 0)
    395         {
    396             RTMemFree (pIf->paEndpoints);
    397             pIf->paEndpoints = NULL;
    398             RTStrFree ((char *)pIf->pszDriver);
    399             pIf->pszDriver = NULL;
    400             RTStrFree ((char *)pIf->pszInterface);
    401             pIf->pszInterface = NULL;
    402             /* next */
    403             pIf++;
    404         }
     413        freeInterfaceMembers (pCfg->paInterfaces, pCfg->bNumInterfaces);
    405414        RTMemFree (pCfg->paInterfaces);
    406415        pCfg->paInterfaces = NULL;
     416        pCfg->bNumInterfaces = 0;
     417
    407418        RTStrFree ((char *)pCfg->pszConfiguration);
    408419        pCfg->pszConfiguration = NULL;
  • trunk/src/VBox/Main/include/USBProxyService.h

    r4071 r5523  
    198198
    199199public:
     200    /**
     201     * Free all the members of a USB interface returned by getDevice().
     202     *
     203     * @param   pIf         Pointer to the interface.
     204     * @param   cIfs        Number of consecutive interfaces pIf points to
     205     */
     206    static void freeInterfaceMembers (PUSBINTERFACE pIf, unsigned cIfs);
     207
    200208    /**
    201209     * Free all the members of a USB device returned by getDevice().
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r5028 r5523  
    248248    }
    249249
    250 #if 0
     250#if 1
    251251    // IUnknown identity test
    252252    ////////////////////////////////////////////////////////////////////////////
     
    326326    EventQueue eventQ;
    327327
     328#if 0
     329    // the simplest COM API test
     330    ////////////////////////////////////////////////////////////////////////////
     331    {
     332        Bstr version;
     333        CHECK_ERROR_BREAK (virtualBox, COMGETTER(Version) (version.asOutParam()));
     334        printf ("VirtualBox version = %ls\n", version.raw());
     335    }
     336#endif
     337
     338#if 0
    328339    // some outdated stuff
    329340    ////////////////////////////////////////////////////////////////////////////
    330341
    331 #if 0
    332342    printf("Getting IHost interface...\n");
    333343    IHost *host;
     
    443453#endif
    444454
    445 #if 1
     455#if 0
    446456    // register the existing hard disk image
    447457    ///////////////////////////////////////////////////////////////////////////
  • trunk/src/VBox/Main/xml/cfgldr.cpp

    r4372 r5523  
    509509    rc = RTStrToUtf16 (pszBaseURI, &m_pwszBaseURI);
    510510    AssertRC (rc);
     511
     512    RTStrFree(pszBaseURI);
    511513}
    512514
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