VirtualBox

Changeset 59127 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Dec 14, 2015 3:56:07 PM (9 years ago)
Author:
vboxsync
Message:

VBoxUSB/win: Minor cleanups and a few more pointer checks after vital memory allocations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp

    r59121 r59127  
    131131        }
    132132
    133         if (version.u32Major != USBDRV_MAJOR_VERSION
    134                 || version.u32Minor <  USBDRV_MINOR_VERSION)
     133        if (   version.u32Major != USBDRV_MAJOR_VERSION
     134            || version.u32Minor <  USBDRV_MINOR_VERSION)
    135135        {
    136136            AssertMsgFailed(("Invalid version %d:%d vs %d:%d\n", version.u32Major, version.u32Minor, USBDRV_MAJOR_VERSION, USBDRV_MINOR_VERSION));
     
    280280
    281281    return VINF_SUCCESS;
    282 }
    283 
    284 static void usbLibDevFree(PUSBDEVICE pDevice)
    285 {
    286     RTStrFree((char*)pDevice->pszAddress);
    287     RTStrFree((char*)pDevice->pszHubName);
    288     if (pDevice->pszManufacturer)
    289         RTStrFree((char*)pDevice->pszManufacturer);
    290     if (pDevice->pszProduct)
    291         RTStrFree((char*)pDevice->pszProduct);
    292     if (pDevice->pszSerialNumber)
    293         RTStrFree((char*)pDevice->pszSerialNumber);
    294     RTMemFree(pDevice);
    295 }
    296 
    297 static void usbLibDevFreeList(PUSBDEVICE pDevice)
    298 {
    299     while (pDevice)
    300     {
    301         PUSBDEVICE pNext = pDevice->pNext;
    302         usbLibDevFree(pDevice);
    303         pDevice = pNext;
    304     }
    305282}
    306283
     
    322299        pDev->enmState = USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
    323300    pDev->enmSpeed = USBDEVICESPEED_UNKNOWN;
    324     pDev->pszAddress = RTStrDup(lpszDrvKeyName);
     301    int rc = RTStrAPrintf((char **)&pDev->pszAddress, "%s", lpszDrvKeyName);
     302    if (RT_FAILURE(rc))
     303        return rc;
     304    pDev->pszBackend = RTStrDup("host");
     305    if (!pDev->pszBackend)
     306    {
     307        RTStrFree((char *)pDev->pszAddress);
     308        return VERR_NO_STR_MEMORY;
     309    }
    325310    pDev->pszHubName = RTStrDup(lpszHubName);
    326311    pDev->bNumConfigurations = 0;
    327312    pDev->u64SerialHash = 0;
    328     pDev->pszBackend = RTStrDup("host");
    329313
    330314    for (; pDrList; pDrList = pDrList->pNext)
     
    351335 *
    352336 *  */
    353             int rc = RTUtf16ToUtf8((PCRTUTF16)pDrList->StrDr.bString, lppszString);
     337            rc = RTUtf16ToUtf8((PCRTUTF16)pDrList->StrDr.bString, lppszString);
    354338            if (RT_FAILURE(rc))
    355339            {
     
    811795
    812796    PUSBDEVICE pDev = (PUSBDEVICE)RTMemAllocZ(sizeof (*pDev));
    813     rc = usbLibDevPopulate(pDev, pConInfo, iPort, lpszName, lpcszHubName, pList);
    814     AssertRC(rc);
    815     if (RT_SUCCESS(rc))
    816     {
    817         pDev->pNext = *ppDevs;
    818         *ppDevs = pDev;
    819         ++*pcDevs;
    820     }
     797    if (RT_LIKELY(pDev))
     798    {
     799        rc = usbLibDevPopulate(pDev, pConInfo, iPort, lpszName, lpcszHubName, pList);
     800        if (RT_SUCCESS(rc))
     801        {
     802            pDev->pNext = *ppDevs;
     803            *ppDevs = pDev;
     804            ++*pcDevs;
     805        }
     806        else
     807            RTMemFree(pDev);
     808    }
     809    else
     810        rc = VERR_NO_MEMORY;
    821811
    822812    if (pCfgDr)
     
    830820        usbLibDevStrDrEntryFreeList(pList);
    831821
    832     return VINF_SUCCESS;
     822    return rc;
    833823}
    834824
     
    870860        for (ULONG i = 1; i <= NodeInfo.u.HubInformation.HubDescriptor.bNumberOfPorts; ++i)
    871861        {
     862            /* Just skip devices for which we failed to create the device structure. */
    872863            usbLibDevGetHubPortDevices(hDev, lpszName, i, ppDevs, pcDevs);
    873864        }
     
    10101001            {
    10111002                /* dbg breakpoint */
    1012                 Assert(0);
     1003                AssertFailed();
    10131004            }
    10141005#endif
     
    12611252
    12621253    /*
    1263      * Register the Window Class and the hitten window create.
     1254     * Register the Window Class and create the hidden window.
    12641255     */
    12651256    WNDCLASS wc;
     
    14671458                                     * We're DONE!
    14681459                                     *
    1469                                      * Juse ensure that the event is set so the
     1460                                     * Just ensure that the event is set so the
    14701461                                     * first "wait change" request is processed.
    14711462                                     */
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