VirtualBox

Ignore:
Timestamp:
Nov 22, 2010 6:12:25 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
68008
Message:

USBLib-win: attempt to fix xtracker 5374

File:
1 edited

Legend:

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

    r34259 r34260  
    26962696
    26972697/**
    2698  * Return all attached USB devices.that are captured by the filter
     2698 * Return all attached USB devices that are captured by the filter
    26992699 *
    27002700 * @returns VBox status code
     
    27062706    USBSUP_GETNUMDEV numdev;
    27072707    PUSBDEVICE pDevice = NULL;
    2708     PUSBDEVICE pCaptured = NULL;
    2709     PUSBDEVICE pList = NULL;
    27102708    Log(("usbLibGetDevices: enter\n"));
    27112709
     
    27982796    Assert(numdev.cUSBDevices == *pcDevices);
    27992797
    2800     if (numdev.cUSBDevices == 0 || *pcDevices == 0)
     2798    if ((int32_t)numdev.cUSBDevices <= 0 || *pcDevices == 0)
    28012799    {
    28022800        /* Only return the host devices */
     
    28102808
    28112809    /* Get the required info for each captured device */
    2812     pCaptured = NULL;
    2813     for (int i = 0; i < (int32_t)numdev.cUSBDevices; i++)
     2810    PUSBDEVICE *ppCaptured = (PUSBDEVICE*)RTMemAllocZ(sizeof(PUSBDEVICE * numDev.cUSBDevices));
     2811    if (!ppCaptured)
     2812        goto failure;
     2813
     2814    uint32_t cCaptured = 0;
     2815    for (uint32_t i = 0; i < numdev.cUSBDevices; i++)
    28142816    {
    28152817        USBSUP_GETDEV dev = {0};
     
    28332835            {
    28342836                pDevice = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE));
    2835                 if (pDevice == NULL)
     2837                if (!pDevice)
    28362838                    goto failure;
    28372839
     
    28472849                Log(("usbLibGetDevices: Detected device vid=%x did=%x rev=%x hispd=%d hash=%s hash=%RX64\n", dev.vid, dev.did, dev.rev, dev.fHiSpeed, dev.serial_hash, pDevice->u64SerialHash));
    28482850
    2849                 /* Insert into the list */
    2850                 pDevice->pNext = pCaptured;
    2851                 if (pCaptured)
    2852                     pCaptured->pPrev = pDevice;
    2853 
    2854                 pCaptured = pDevice;
    2855 
     2851                ppCaptured[i] = pDevice;
     2852                cCaptured++;
    28562853            }
    28572854
     
    28622859    }
    28632860
    2864     if (!pCaptured)
     2861    if (!cCaptured)
    28652862    {
    28662863        /* Only return the host devices */
     
    28712868    }
    28722869
    2873     /* 3: Add all host devices to array of captured devices; obviously making sure there are no duplicates */
    2874     Assert(pHostDevices && pCaptured);
    2875     pList = pCaptured;
     2870    /* 3: Go through the list of captured devices, lookup the corresponding device
     2871     *    in the list of host devices and update the information there. */
     2872    Assert(pHostDevices);
    28762873    for (uint32_t i = 0; i < numdev.cUSBDevices; i++)
    28772874    {
    2878         uint32_t j;
     2875        char *pszDeviceRegPath = usblibQueryDeviceRegPath(i);
     2876        Assert(pszDeviceRegPath);
    28792877
    28802878        pDevice = pHostDevices;
    2881         Assert(pDevice);
    2882 
    2883         for (j = 0; j < cHostDevices; j++)
    2884         {
    2885             char *pszDeviceRegPath = usblibQueryDeviceRegPath(i);
    2886 
    2887             Assert(pszDeviceRegPath);
     2879        for (uint32_t j = 0; j < cHostDevices; j++)
     2880        {
    28882881            if (pszDeviceRegPath)
    28892882            {
     
    29102903
    29112904            pDevice->enmState = USBDEVICESTATE_HELD_BY_PROXY;
    2912             pDevice->enmSpeed = pList->enmSpeed;    // @todo: Is that right?
     2905            if (ppCaptured[i])
     2906                pDevice->enmSpeed = ppCaptured[i]->enmSpeed;    // @todo: Is that right?
    29132907            RTStrFree(pDevice->pszAltAddress);
    29142908            pDevice->pszAltAddress = (char *)pDevice->pszAddress;
    29152909            pDevice->pszAddress = RTStrDup(usblibQueryDeviceName(i));
    29162910        }
    2917         pList = pList->pNext;
    29182911    }
    29192912    *pcDevices = cHostDevices;
    29202913
    29212914    /* Free captured devices list */
    2922     pDevice = pCaptured;
    2923     while (pDevice)
    2924     {
    2925         PUSBDEVICE pOldDev = pDevice;
    2926 
    2927         if (pDevice->pszAddress)
     2915    for (uint32_t i = 0; i < numdev.cUSBDevices; i++)
     2916    {
     2917        pDevice = ppCaptured[i];
     2918        if (pDevice)
     2919        {
    29282920            RTMemFree((void *)pDevice->pszAddress);
    2929         if (pDevice->pszAltAddress)
    29302921            RTStrFree(pDevice->pszAltAddress);
    2931         if (pDevice->pszHubName)
    29322922            RTStrFree(pDevice->pszHubName);
    2933         if (pDevice->pszManufacturer)
    29342923            RTMemFree((void *)pDevice->pszManufacturer);
    2935         if (pDevice->pszProduct)
    29362924            RTMemFree((void *)pDevice->pszProduct);
    2937         if (pDevice->pszSerialNumber)
    29382925            RTMemFree((void *)pDevice->pszSerialNumber);
    2939 
    2940         pDevice = pDevice->pNext;
    2941 
    2942         RTMemFree(pOldDev);
    2943     }
     2926            RTMemFree(pDevice);
     2927        }
     2928    }
     2929    RTMemFree(ppCaptured);
    29442930
    29452931    Log(("usbLibGetDevices: returns %d devices\n", *pcDevices));
     
    29912977
    29922978failure:
     2979    /* free host devices */
    29932980    pDevice      = pHostDevices;
    29942981    pHostDevices = NULL;
    29952982    while (pDevice)
    29962983    {
    2997         PUSBDEVICE pOldDev = pDevice;
    2998 
    2999         if (pDevice->pszAddress)
     2984        PUSBDEVICE pNext = pDevice->pNext;
     2985
     2986        RTMemFree((void *)pDevice->pszAddress);
     2987        RTMemFree((void *)pDevice->pszManufacturer);
     2988        RTMemFree((void *)pDevice->pszProduct);
     2989        RTMemFree((void *)pDevice->pszSerialNumber);
     2990        RTMemFree(pDevice);
     2991
     2992        pDevice = Next;
     2993    }
     2994
     2995    /* free captured devices */
     2996    for (uint32_t i = 0; i < numdev.cUSBDevices; i++)
     2997    {
     2998        pDevice = ppCaptured[i];
     2999        if (pDevice)
     3000        {
    30003001            RTMemFree((void *)pDevice->pszAddress);
    3001         if (pDevice->pszManufacturer)
    30023002            RTMemFree((void *)pDevice->pszManufacturer);
    3003         if (pDevice->pszProduct)
    30043003            RTMemFree((void *)pDevice->pszProduct);
    3005         if (pDevice->pszSerialNumber)
    30063004            RTMemFree((void *)pDevice->pszSerialNumber);
    3007 
    3008         pDevice = pDevice->pNext;
    3009 
    3010         RTMemFree(pOldDev);
    3011 
    3012         if (pDevice == NULL && pCaptured)
    3013         {
    3014             pDevice   = pCaptured;
    3015             pCaptured = NULL;
    3016         }
    3017     }
     3005            RTMemFree(pDevice);
     3006        }
     3007    }
     3008    RTMemFree(ppCaptured);
    30183009
    30193010    *ppDevices = NULL;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette